BarCodeKit – Cocoanetics https://www.cocoanetics.com Our DNA is written in Swift Fri, 14 Jul 2023 15:20:48 +0000 en-US hourly 1 https://wordpress.org/?v=6.4.3 39982308 BarCodeKit 1.4.0 https://www.cocoanetics.com/2023/07/barcodekit-1-4-0/ https://www.cocoanetics.com/2023/07/barcodekit-1-4-0/#comments Fri, 14 Jul 2023 15:20:47 +0000 https://www.cocoanetics.com/?p=10767 Next month marks the 10 year anniversary of BarCodeKit. It’s been like two years of slumber since the last release. It was available via Cocoapods and direct via GitHub, but lately several developers voiced interest for it to be available as Swift Package.

Like most of my open source frameworks on GitHub, BarCodeKit is written in Objective-C, but that doesn’t mean it couldn’t be available as Swift Package. Xcode automagically morphs everything to look Swift-native and so an implementer of such a package wouldn’t be the wiser.

To make it a Swift package I needed to clean up some ways how system frameworks are imported, what headers are imported where and most importantly I had to ditch the precompiled headers (PCH) which aren’t supported by SPM.

Once that was done I had a package that would build without complains with a simple swift build. But if you also have unit tests then you want those to be conformant with the SPM ecosystem as well. This involves mostly adding the resources – if any – required by the test cases and adding a test target to the package.swift.

I was making some changes and then running swift test, rinse and repeat. Every iteration you find a few more minor things you have to address. Until in the end both building and testing the package go without errors.

The outcome of this exercise – I like to tell myself to justify all this time spent – is that your importing and setup has become more robust.

So here we go. I submitted the new 1.4.0 version to Cocoapods, tagged it on GitHub as a release on the master branch, and finally submitted an addition requisition to the Swift Package Index. It’s been a while since I had done that last (couple of years actually) so I was confused initially by a GitHub bot stating that some additional review was required.

But that was resolved in the end by Mr. Dave Verwer himself approving the merge. Many thanks, I’m honored, Sir!

And in case you wonder why it says “unknown license” on Swift Package Index… this is because the license is a combination of my normal license and a full commercial license. Basically purchasing my book grants you a perpetual full commercial license. If you don’t want to do that there’s my standard open source license. Thereby you have to attribute to me when using BarCodeKit in your apps, or buy a non-attribution license on my parts store.

]]>
https://www.cocoanetics.com/2023/07/barcodekit-1-4-0/feed/ 4 10767
BarCodeKit 1.3.3 https://www.cocoanetics.com/2021/05/barcodekit-1-3-3/ https://www.cocoanetics.com/2021/05/barcodekit-1-3-3/#comments Wed, 05 May 2021 07:18:12 +0000 https://www.cocoanetics.com/?p=10697 Apparently I made a mistake in the previous release forgetting to include several commits mentioned in the release notes. It only took about 3 years for somebody to notice.

Changes

  • FIXED: some warnings related to duplicate entries in the encoding table for Code 39 and Code 93 Full ASCII
  • FIXED: Previous version was missing several commits mentioned in the release notes

I think what might have happened is that I got confused with the tags and versions. But now all the changes are included in 1.3.3.

Ivan asked:

On the site, I can see that you have mentioned that with the buying of your book the license for the library is free, is this still valid? What kind of license I will get if I buy your book?

Yes, that still works. The license says that you can use the library without attribution for your own apps. The library is open source so everybody can use it, but they have to include the BSD License text in the app settings. With the non-attribution license you don’t have to mention BarCodeKit or Cocoanetics at all. I normally charge 75 Euros for this kind of license, so the book is a really good deal. 🙂

The new version is tagged on GitHub as well as published on Cocoapods Trunk.

]]>
https://www.cocoanetics.com/2021/05/barcodekit-1-3-3/feed/ 15 10697
BarCodeKit 1.3.1 https://www.cocoanetics.com/2016/06/barcodekit-1-3-1/ https://www.cocoanetics.com/2016/06/barcodekit-1-3-1/#respond Fri, 03 Jun 2016 16:33:32 +0000 https://www.cocoanetics.com/?p=10236 BarCodeKit can generate lots of different kinds of 1D barcodes. The previous update coincided with the release the Barcodes with iOS book. This release rolls up a few tweaks and adds a new rendering option.

Changes

  • ADDED: option to specify explicit barcode size
  • FIXED: incorrectly named methods and comments not matching the class name

Thanks to Martin Kötzing and “ebaker355” for their contributions!

The new rendering options let you specify a higher resolution width or height as opposed to the one that get’s calculated from the multiple and minimum size. This is useful for when you want to render a barcode into a higher resolution image.

The update is available on Cocoapods and tagged on GitHub.

]]>
https://www.cocoanetics.com/2016/06/barcodekit-1-3-1/feed/ 0 10236
BarCodeKit 1.3.0 https://www.cocoanetics.com/2014/10/barcodekit-1-3-0/ https://www.cocoanetics.com/2014/10/barcodekit-1-3-0/#respond Fri, 10 Oct 2014 15:10:01 +0000 http://www.cocoanetics.com/?p=9344 The previous release to BarCodeKit was almost exactly one year ago, when I was just about getting started with writing my book.

Changes

  • FIXED: Assertion failure when draing barcodes into graphics context with translated CTM
  • ADDED: Error messages on barcode generation localized in English, Japanese and German
  • ADDED: BCKCodeDrawingReduceBleedOption for reducing bleed on thermo printers
  • ADDED: POSTNET Implementation
  • ADDED: ISMN Implementation
  • ADDED: Added additional range and length checks to ISBN and ISMN
  • ADDED: Internal support for barcodes with partial bars
  • ADDED: BCKCodeDrawingCaptionFontPointSizeOption for specifying caption font size
  • ADDED: Share button to Demo which exports a PDF of any configured barcode via activity view
  • CHANGED: Internal implemention from NSString to BCKBarString
  • CHANGED: Migrated unit tests to XCTest

The reason for the long time since the last release was that I wanted to use the component in a practical application. Chapter 5 in my book demonstrates how to print a single 1D barcode over AirPrint to a label printer. This was also the reason for adding the option to reducing thermal bleed. So over the last year the component was honed, refactored, saw the GM of Xcode 5 and Xcode 6 and was polished on multiple levels.

Special thanks go to Geoff Breemer who contributed all the new barcode implementations. BarCodeKit now supports the following (blue ones scannable by iOS).

  • Codabar
  • Code 11
  • Code 39 (plain, modulo 43, full ASCII)
  • Code 93
  • Code 128
  • Facing Identification Mark (FIM)
  • GTIN family: EAN-8, EAN-13, UPC-A, UPC-E, EAN-2, EAN-5
  • ISBN10 and ISBN13
  • ISMN
  • ISSN
  • MSI (Modified Plessey)
  • Pharmacode One Track
  • POSTNET
  • Standard/Industrial 2 of 5

Thanks also go to Brendan Duddridge who made the barcode generation error messages localisable as well as contributed a Japanese strings file. I myself did a German language translation. Brendan’s famous database app Tap Forms leverages BarCodeKit in its new label printing engine:

Tap Forms for Mac version 3.0 will feature a brand new label printing engine which takes advantage of the excellent BarCodeKit framework to provide support for up to 24 different barcode symbologies.

Here’s what’s new:

• OS X 10.10 Yosemite compatibility
• All new look and feel.
• Live form template editing.
• New Label printing engine which includes more then 1000 Avery® label templates.
• Customize your own labels.
• Print 24 different types of barcodes including ISBN, UPC, Code 39, QR code, EAN, and more!
• More advanced calculation field type with support for returning a Number, Text, or Date value.
• Zoom in or out on custom layouts.
• Customizable toolbar.
• Import and export Excel Workbook XLSX files.

Tap Forms for Mac is expected to be released shortly after the release of OS X 10.10 Yosemite.

The update is tagged on the private repo (for purchasers of repo access), will be available to owners of my book for free and is also available via our private Cocoapods repo.

]]>
https://www.cocoanetics.com/2014/10/barcodekit-1-3-0/feed/ 0 9344
BarCodeKit 1.2.0 https://www.cocoanetics.com/2013/10/barcodekit-1-2-0/ https://www.cocoanetics.com/2013/10/barcodekit-1-2-0/#comments Fri, 04 Oct 2013 14:16:54 +0000 http://www.cocoanetics.com/?p=8723 This update to BarCodeKit establishes full compatibility for iOS and Mac. You can now use BarCodeKit to generate images of bar codes for display and print on both platforms with identical features.

Changes

  • ADDED: Mac Compatibility
  • ADDED: Demo App for Mac
  • ADDED: Option to specify barcode image background color
  • ADDED: Facing Identification Mark Code
  • ADDED: EAN-2 and EAN-5 Supplements
  • ADDED: Standard 2 of 5 Code
  • ADDED: Pharmacode One-Track Code
  • ADDED: Optimized Presentation for UPC-A
  • ADDED: ISSN Code
  • ADDED: ISBN Code
  • CHANGED: Codes now check if they are able to encode content and return an error message with the reason if not

All of the additional barcode types were implemented by Geoff Breemer. Many thanks!

The project now comes with both a Demo App for iOS as well as one for Mac that allows you to experiment with the rendering settings.

BarCodeKit Mac Demo

BarCodeKit iOS Demo

The update is tagged on the repository and also available via private CocoaPods spec.  The spec – just like the entire project – is now also for both platforms.

]]>
https://www.cocoanetics.com/2013/10/barcodekit-1-2-0/feed/ 7 8723
BarCodeKit 1.1.0 https://www.cocoanetics.com/2013/09/barcodekit-1-1-0/ https://www.cocoanetics.com/2013/09/barcodekit-1-1-0/#comments Mon, 09 Sep 2013 15:45:02 +0000 http://www.cocoanetics.com/?p=8644 As of this version BarCodeKit gains implementations for all of the most important 1D symbologies. Most of the work on this release was done by Jaanus Siim and Geoff Breemer in exchange for licenses to use this library for their own projects. BarCodeKit 1.1 is a free update for existing users and available for purchase on our Parts Store.

Changes

  • ADDED: Code 128 Implementation
  • ADDED: Code 93 Full ASCII Implementation
  • ADDED: Code 11 Implementation
  • ADDED: Code 39 Variants mod 43, Full ASCII (with and without mod 43)
  • ADDED: New drawing option for customizing the caption font
  • FIXED: Caption descenders get cut off for lowercase ASCII characters
  • CHANGED: Replaced caption drawing with Core Text
  • CHANGED: All codes cache their code characters after creating them
  • CHANGED: Demo App much improved

The new demo app has a table view that shows all sub-classes of BCKCode which is the root class for all code implementations.

New Demo Menu

The pages for the individual codes inquire the code classes which drawing options are supported and allow you to play around with the settings.

New Demo App

All polishing of the Demo App was done by Geoff Breemer.  Geoff also contributed the implementations for Code 11, Code 39 Variants as well as Code 93. Thank you very much!

Code 128 is way more complex than all the other codes, so I want to also thank Jaanus Siim for tackling the implementation there. I was over the moon when he offered to implement this because I was afraid of having to do that myself being overwhelmed by the work necessary. Jaanus did an outstanding job there as well.

The biggest change I implemented myself was switching from using the iOS 7 text drawing methods to basic Core Text. This allowed us to drop the iOS deployment target back to iOS 5.

Code 128

Changing the text drawing to Core Text should also make it Mac-compatible, though I didn’t look into that in detail. For this it would be nice to have somebody with a Mac-based work flow who would like to implement BarCodeKit.

We are very happy with how BarCodeKit has grown. If you have a fun use case for it or have requirements that it doesn’t meet please don’t hesitate to contact us.

]]>
https://www.cocoanetics.com/2013/09/barcodekit-1-1-0/feed/ 6 8644
BarCodeKit 1.0.1 https://www.cocoanetics.com/2013/08/barcodekit-1-0-1/ https://www.cocoanetics.com/2013/08/barcodekit-1-0-1/#comments Fri, 23 Aug 2013 14:23:19 +0000 http://www.cocoanetics.com/?p=8596 Not much time has passed since the initial release of BarCodeKit. But time enough for Mr. Andy Qua to generously provide an implementation for the Interleaved 2of5 code.

Changes

  • ADDED: Implementation for Interleaved 2 of 5 Code

The Interleaved 2of5 Code is apparently used in scenarios where you need to represent a variable-length number. One use case for that might be baggage tracking at airports.

Interleaved 2of5 generated with BarCodeKit

Andy commented his experience implementing this code within the structure of the BarCodeKit as such:

“Your library was nice and easy to understand – logical and obvious!” – Andy Qua

If you would like to contribute an implementation for a code type not yet represented I am interested in trading you a free license of BarCodeKit for use in your own apps for it.

The update is tagged on the private repo as well available via our private CocoaPods repo.

]]>
https://www.cocoanetics.com/2013/08/barcodekit-1-0-1/feed/ 2 8596
Announcing BarCodeKit https://www.cocoanetics.com/2013/08/announcing-barcodekit/ https://www.cocoanetics.com/2013/08/announcing-barcodekit/#comments Mon, 19 Aug 2013 12:47:49 +0000 http://www.cocoanetics.com/?p=8569 iOS7 will have the ability to scan 1D and 2D bar codes built-in. The same is true for generating 2D bar codes. Which begs the question why Apple opted to omit support for creating 1D bar codes. (rdar://14694904)

One second hand explanation I heard was that laser-based scanners might have trouble reading 1D codes from the screen of an iPhone, whereas 2D codes require a camera anyway and therefore can be easily scanned even from a display.

While this explains the omission to a certain degree, I don’t buy it. I can think of many scenarios where you would want to print a 1D bar code, or put it into a PDF that is supposed to printed. Also, as CCD-based scanners become more prevalent they will soon be available in larger numbers than laser-based scanners.

In short, I am seeing a niche that is not being served. Thus I’m announcing BarCodeKit.

BarCodeKit is supposed to allow for generating 1D bar codes for whatever use you might have for them in your apps.

Of course there are other libraries. Jeff LaMarche famously created CocoaBarCodes, which was last updated in May 2009. As you can see from the code it is targeting OS X. There is NetShade’s fork of this with some improvements, but abandoned in January 2013, which a long to do list. There are several severe issues with these two projects, for the most part they are Mac-only. Netshade removed the caption printing capability to make it iOS compatible, but never fixed that. And it doesn’t do ARC. And it is in much need of a ground-up rewrite. And so much more …

I got the fork to run on my iOS device, but it didn’t even produce correct codes. This is where my research stopped.

So I decided to start BarCodeKit and structure the whole thing in a way that is easy to understand and extend. I like to re-invent the wheel wherever feasible if it teaches me something and the outcome is better than the original wheel. Better insofar as that it is using modern object-oriented technologies, ARC, is platform-independent and simply the only thing you want to use for the purpose.

What Works

At the time of this writing I have the most basic bar code types done. Those include the ones that are used to represent products codes on physical products. Code 39 I found in use on a Netgear product label where it specifies MAC-address, serial number and product code.

EAN-13 / UPC-A

EAN13 generated with BarCodeKit

EAN-8

EAN8 generated with BarCodeKit

UPC-E

UPC-E generated with BarCodeKit

Code39

Code39 generated with BarCodeKit

Project Structure

I structured the codes around individual “code characters” which are a pattern of bars described by a bit string. All characters derive some basic functionality from BCKCodeCharacter. All codes share BCKCode as root.

BarCodeKit Project Structure

All characters know what pattern of bits (1 for bar, 0 for space) is representing them. This enables all drawing to be BCKCode.

From implementing what we got so far I learned that there are several different things people might want to customize for output of their bars. Because of this I didn’t implement a fixed way to draw them, but allow the user to pass rendering options. The codes are model objects and don’t deal with views, instead they have a method sizeWithOptions: and renderInContext:options: that allows you either provide a PDF or a bitmap context to draw the bar code into.

For example to create a bitmap of code you would use this code, provided in UIImage (BarCodeKit) category.

+ (UIImage *)imageWithBarCode:(BCKCode *)barCode options:(NSDictionary *)options
{
   CGSize neededSize = [barCode sizeWithRenderOptions:options];
 
   UIGraphicsBeginImageContextWithOptions(neededSize, NO, 0);
   CGContextRef context = UIGraphicsGetCurrentContext();
 
   [barCode renderInContext:context options:options];
 
   UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();
 
   return image;
}

The reason for this approach is that typically a size of the output bar code is related to the width of the bars. If you make the bar width thicker, then whole code would grow in required size. If you want a larger bitmap you would increase the bar width multiplier. Also the EAN variants typically have a standard aspect ratio which increases the needed size, whereas Code 39 you normally want to have with a fixed height.

So far these options are implemented:

  • BCKCodeDrawingBarScaleOption: Multiplier for the bar width (default 1)
  • BCKCodeDrawingPrintCaptionOption: Whether the code caption should be printed (default NO)
  • BCKCodeDrawingMarkerBarsOverlapCaptionPercentOption: How many percent of the caption height are covered by elongated marker bars (default 1.0)
  • BCKCodeDrawingFillEmptyQuietZonesOption: Whether quiet zones should be filled with angle brackes (default NO)
  • BCKCodeDrawingDebugOption: Whether the caption areas should be tinted for debugging (default NO)

As time goes one I am certain that additional options will become necessary, like to set a fixed bar height or specify colors. Those will depend on the use cases that developers will want to use it for.

How to Use

BarCodeKit is very simple to implement. You create an instance of the code you want to generate and then call the above mentioned category method.

NSDictionary *options = @{BCKCodeDrawingBarScaleOption: @(2)};
BCKEAN13Code *code = [[BCKEAN13Code alloc] initWithContent:@"9780596516178"];
imageView.image = [UIImage imageWithBarCode:code options:options];

Of course there are many more things to do with this, like to add proper unit tests and additional codes, like Code128. But again, those will have to largely depend on public interest in this framework.

I have implemented a simple demo app which lets you play with some of the options to see their effect.

BarCodeKit Demo App

As work progresses on BarCodeKit this might change quite a bit, to accommodate additional codes and code-specific options.

Update: Documentation is now available.

The Future

In the near term future BarCodeKit will remain closed-source to preserve the competitive advantage that it provides to people who are willing to spend a little money on acquiring a license. Introductory price will be 150 Euros, which will give you full access to the private git repository where it is being developed.

If you are interested in adding features (i.e. additional bar codes) I would waive the fee in exchange for your contributions. It largly depends on the interest of the community in which direction this project will evolve. We will see, however for now I need to make a little bit of money with it.

Either way, please contact me if you have a project that would benefit of BarCodeKit.

]]>
https://www.cocoanetics.com/2013/08/announcing-barcodekit/feed/ 20 8569