Formats Zig Reference Documentation
Formats
Current Version: 11.7.0
Markdown version of this page for AI tools (v 11.7.0) · all AI docs
Chilkat.Formats
Versions 1–40, error-correction levels L/M/Q/H, automatic or explicit version and mask, numeric/alphanumeric/byte modes, ECI, structured append. Integer-pixel modules, px/mm/in/pt units with DPI, quiet zone, padding, rotation, colors with opacity, caption text, size limits with shrink-to-fit. Returned inline as base64 or SVG text, or written to files (numbered file sets for structured append). Optional module bit-matrix and reusable definition.
See the Barcode / QR Code Generation Overview
for the complete documentation with examples and sample images.
A collection of data-format operations, starting with barcode and QR code generation.
Chilkat.Formats is not string, number or date display formatting. It groups operations on
well-defined data formats behind a small number of JSON-driven methods, so the class can grow by adding a
method per format family without adding a public class for each feature. Introduced in v11.7.0 with the
barcode feature methods Barcode and QrCode.
QR Code generation
Precise rendering
PNG or SVG output
Measure and validate
measure reports exact geometry without rendering; validate checks a request; capabilities describes what the build supports.method(op, jsonIn, jsonOut). Requests are
checked strictly (unknown options are rejected, not ignored) and every failure has a stable error code with the
JSON Pointer of the offending member.
Object Creation
// Add the package once:
// zig fetch --save https://chilkatdownload.com/11.7.0/chilkat-zig-11.7.0.tar.gz
// and in build.zig:
// const chilkat = b.dependency("chilkat", .{ .target = target, .optimize = optimize });
// exe.root_module.addImport("chilkat", chilkat.module("chilkat"));
const chilkat = @import("chilkat");
// Once per process, before any other Chilkat call:
try chilkat.unlockBundle("Anything for 30-day trial");
const formats = try chilkat.Formats.init();
defer formats.deinit();Creates the underlying native Chilkat object. Formats is a one-pointer struct passed by value; copying it copies the handle (two names for one object). Returns error.OutOfMemory if the library could not allocate the object. Use an object from one thread at a time; it may be handed from one thread to another.
Releases the native object. Call it exactly once per object (usually with defer); the handle is invalid afterwards. Objects returned by methods are owned by the caller too and are released the same way.
Wraps a handle obtained from the C API (chilkat.c.CkFormats), taking ownership of it. The struct's handle field goes the other way, for anything the Zig API does not cover.
Errors and memory
Methods that can fail return an error union: a method whose only outcome is success or failure returns Error!void; a method producing a string returns (Error || Allocator.Error)![:0]u8; a method producing an object returns Error!T. chilkat.Error is error{ChilkatFailed}; the reason for a failure is in getLastErrorText, and the object remains usable. Properties never fail, and methods that answer a question (hasMember, isUnlocked, ...) return a plain bool.
String arguments are [:0]const u8 (UTF-8; string literals can be passed as is). String results are copies allocated with the allocator argument and owned by the caller, so they stay valid across later calls on the same object.
const text = formats.someMethod(allocator, ...) catch |err| {
const why = try formats.getLastErrorText(allocator);
defer allocator.free(why);
std.debug.print("{s}\n", .{why});
return err;
};
defer allocator.free(text);
Properties
DebugLogFilePath
pub fn getDebugLogFilePath(self: Formats, allocator: Allocator) Allocator.Error![:0]u8
pub fn setDebugLogFilePath(self: Formats, value: [:0]const u8) void
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
LastErrorHtml
pub fn getLastErrorHtml(self: Formats, allocator: Allocator) Allocator.Error![:0]u8
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
pub fn getLastErrorText(self: Formats, allocator: Allocator) Allocator.Error![:0]u8
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
pub fn getLastErrorXml(self: Formats, allocator: Allocator) Allocator.Error![:0]u8
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
pub fn getLastMethodSuccess(self: Formats) bool
pub fn setLastMethodSuccess(self: Formats, value: bool) void
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
VerboseLogging
pub fn getVerboseLogging(self: Formats) bool
pub fn setVerboseLogging(self: Formats, value: bool) void
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
pub fn getVersion(self: Formats, allocator: Allocator) Allocator.Error![:0]u8
Methods
Barcode
Runs one barcode operation and returns the result as JSON. op is the operation: "generate" (encode the payload, lay out the symbol and render a PNG or SVG), "measure" (encode and lay out only, reporting the exact geometry and whether the symbol fits), "validate" (examine a request's definition, capacity or layout) or "capabilities" (describe the symbologies, operations, formats and limits this build implements). json_in is the request: it names the symbology (currently "qr"), the payload (text or base64 binary) and optional encoding, render, output and limits groups. json_out is replaced with the response. Every response carries errors[] and warnings[]; a successful "generate" also returns symbols[] (the encoding actually selected), measurements[] (pixel geometry) and outputs[] (the image as base64 or SVG text, or the path of the file written).
Returns true when the operation completed successfully. Returns false when the request was rejected or execution failed; errors[0] then holds a stable code, the JSON Pointer path of the offending request member and a message.
The request and response vocabulary (payload types, QR version, error correction, mask, ECI, structured append, module size and physical units, quiet zone, rotation, colors, captions, PNG/SVG output, file writing, limits and error codes) is documented in full, with examples and sample images, at the links below.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.
QrCode
The same as Barcode with the symbology defaulting to "qr", so the smallest request is { "payload": { "text": "..." } }. op is the operation ("generate", "measure", "validate" or "capabilities"), json_in the request and json_out the response. Identical requests to QrCode and Barcode produce identical results; a request naming a symbology outside the QR family is rejected.
Generates QR Code (Model 2) symbols in versions 1-40 with error-correction levels L, M, Q and H, automatic or explicit version and mask selection, numeric, alphanumeric and byte modes, optional ECI, and structured append of up to 16 symbols. Output is PNG or SVG, returned inline (base64 or SVG text) and/or written to files.
Returns true when the operation completed successfully, otherwise false with the reason in errors[0] of json_out (code, JSON Pointer path and message). See the links below for the complete documentation of every option, with examples and sample images.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.