Codeunit 9209 IDA 1D I2of5 Encoder, source in 26

Source242526272829metadata in 26

src/System Application/App/Barcode/src/IDAutomation 1D Provider/Encoders/IDA1DI2of5Encoder.Codeunit.al45 lines, Copyright (c) Microsoft Corporation. MIT

// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace System.Text;

using System;
using System.Utilities;

/// <summary>
/// ITF barcode font implementation from IDAutomation
/// from: https://www.idautomation.com/barcode-fonts/interleaved-2of5/
/// Interleaved 2 of 5 (ITF) is a numeric only barcode used to encode pairs of numbers into a self-checking, high-density barcode format
/// </summary>
codeunit 9209 "IDA 1D I2of5 Encoder" implements "Barcode Font Encoder"
{
    Access = Internal;
    InherentEntitlements = X;
    InherentPermissions = X;

    procedure EncodeFont(InputText: Text; var BarcodeEncodeSettings: Record "Barcode Encode Settings"): Text
    var
        DotNetFontEncoder: DotNet FontEncoder;
    begin
        DotNetFontEncoder := DotNetFontEncoder.FontEncoder();

        if BarcodeEncodeSettings."Use mod 10" then
            exit(DotNetFontEncoder.I2of5Mod10(InputText));

        exit(DotNetFontEncoder.I2of5(InputText));
    end;

    procedure IsValidInput(InputText: Text; var BarcodeEncodeSettings: Record "Barcode Encode Settings"): Boolean;
    var
        RegexPattern: Codeunit Regex;
    begin
        if InputText = '' then
            exit(false);

        // match any string containing pairs of digits
        exit(RegexPattern.IsMatch(InputText, '^([0-9]{2})+?$'));
    end;
}