barcode.plugins.inc in Barcode 6.2
Same filename and directory in other branches
Code to load barcode symbology plugins
File
includes/barcode.plugins.incView source
<?php
/**
* @file
* Code to load barcode symbology plugins
*/
/**
* Builds and return a list of all plugins available in the system.
*
* @return Nested array of plugins, grouped by type and
*/
function barcode_discover_plugins() {
$plugins['ean'] = array(
'UPC-A' => t('UPC-A'),
'EAN-13' => t('EAN-13'),
'ISBN' => t('ISBN'),
);
$plugins['ean8'] = array(
'EAN-8' => t('EAN-8'),
);
$plugins['upce'] = array(
'UPC-E' => t('UPC-E'),
);
$plugins['s2o5'] = array(
'S2O5' => t('Standard 2 of 5'),
'I2O5' => t('Industrial 2 of 5'),
);
$plugins['i25'] = array(
'I25' => t('Interleaved 2 of 5'),
);
$plugins['postnet'] = array(
'POSTNET' => t('Postnet'),
);
$plugins['codabar'] = array(
'CODABAR' => t('Codabar'),
);
$plugins['code128'] = array(
'CODE128' => t('Code 128'),
);
$plugins['code39'] = array(
'CODE39' => t('Code 39'),
);
$plugins['code93'] = array(
'CODE93' => t('Code 93'),
);
return $plugins;
}
/**
* Return the plugin filename containing the given encoding.
*/
function barcode_load_plugin($encoding_name) {
$plugins = barcode_discover_plugins();
foreach ($plugins as $plugin => $encodings) {
foreach ($encodings as $encoding => $display_string) {
if ($encoding == $encoding_name) {
module_load_include('inc', 'barcode', 'plugins/' . $plugin);
return $plugin;
}
}
}
return '';
}
function barcode_plugin_generate_image($plugin, $barcode, $settings) {
$gen_function = 'barcode_' . $plugin . '_barcode';
$gen_function($barcode, $settings);
}
function barcode_plugin_max_length($encoding_name) {
$plugin = barcode_load_plugin($encoding_name);
$max_length_function = 'barcode_' . $plugin . '_max_length';
if (function_exists($max_length_function)) {
return $max_length_function($encoding_name);
}
}
/**
* Creates or return the plugin filename containing the given encoding.
*/
function barcode_generate_image($barcode) {
$filename_noformat = file_create_path($barcode['default_path']) . '/' . $barcode['value'] . $barcode['encoding'];
$filename = $filename_noformat . '.' . $barcode['image_format'];
// First check if the images already exists.
if (!file_exists($filename)) {
$plugin = barcode_load_plugin($barcode['encoding']);
$settings->encode = $barcode['encoding'];
$settings->height = $barcode['height'];
$settings->scale = $barcode['scale'];
$settings->color = array(
hexdec(substr($barcode['barcolor'], 1, 2)),
hexdec(substr($barcode['barcolor'], 3, 2)),
hexdec(substr($barcode['barcolor'], 5, 2)),
);
$settings->bgcolor = array(
hexdec(substr($barcode['bgcolor'], 1, 2)),
hexdec(substr($barcode['bgcolor'], 3, 2)),
hexdec(substr($barcode['bgcolor'], 5, 2)),
);
$settings->font = $barcode['font'];
$settings->format = $barcode['image_format'];
$settings->filename_no_format = $filename_noformat;
$settings->n2w = 2;
barcode_plugin_generate_image($plugin, $barcode['value'], $settings);
drupal_set_message(t('The %barcode barcode image has been generated using %encoding encoding.', array(
'%barcode' => $barcode['value'],
'%encoding' => $barcode['encoding'],
)));
}
if (!file_exists($filename)) {
return FALSE;
}
return $filename;
}
function barcode_check_digit($barnumber, $number) {
$csum_total = 0;
// The checksum working variable starts at zero
// If the source message string is less than 12 characters long, we make it
// 12 characters
if (strlen($barnumber) < $number) {
$barnumber = str_pad($barnumber, $number, "0", STR_PAD_LEFT);
}
// Calculate the checksum value for the message
for ($i = 0; $i < strlen($barnumber); $i++) {
if ($i % 2 == 0) {
$csum_total = $csum_total + 3 * intval($barnumber[$i]);
}
else {
$csum_total = $csum_total + intval($barnumber[$i]);
}
}
// Calculate the checksum digit
if ($csum_total % 10 == 0) {
$checksum_digit = '';
}
else {
$checksum_digit = 10 - $csum_total % 10;
}
return $barnumber . $checksum_digit;
}
Functions
Name | Description |
---|---|
barcode_check_digit | |
barcode_discover_plugins | Builds and return a list of all plugins available in the system. |
barcode_generate_image | Creates or return the plugin filename containing the given encoding. |
barcode_load_plugin | Return the plugin filename containing the given encoding. |
barcode_plugin_generate_image | |
barcode_plugin_max_length |