/** * */ function caGenerateBarcode($ps_value, $pa_options = null) { $ps_barcode_type = caGetOption('type', $pa_options, 'code128', array('forceLowercase' => true)); $pn_barcode_height = caConvertMeasurementToPoints(caGetOption('height', $pa_options, '9px')); $vs_tmp = null; switch ($ps_barcode_type) { case 'qr': case 'qrcode': $vs_tmp = tempnam(caGetTempDirPath(), 'caQRCode'); $vs_tmp2 = tempnam(caGetTempDirPath(), 'caQRCodeResize'); if (!defined('QR_LOG_DIR')) { define('QR_LOG_DIR', false); } if ($pn_barcode_height < 1 || $pn_barcode_height > 8) { $pn_barcode_height = 1; } QRcode::png($ps_value, "{$vs_tmp}.png", QR_ECLEVEL_H, $pn_barcode_height); return $vs_tmp; break; case 'code128': case 'code39': case 'ean13': case 'int25': case 'postnet': case 'upca': $o_barcode = new Barcode(); $vs_tmp = tempnam(caGetTempDirPath(), 'caBarCode'); if (!($va_dimensions = $o_barcode->draw($ps_value, "{$vs_tmp}.png", $ps_barcode_type, 'png', $pn_barcode_height))) { return null; } return $vs_tmp; break; default: // invalid barcode break; } return null; }
function render($po_pdf, $pn_x = null, $pn_y = null) { switch (get_class($this->opo_form)) { case 'PrintForms': if ($va_element_info = $this->opa_element_info) { $vn_x = $this->opo_form->getValueInPoints($va_element_info['left']); $vn_y = $this->opo_form->getFormSetting('pageHeight') - $this->opo_form->getValueInPoints($va_element_info['top']); } break; case 'PrintSubForms': if ($va_element_info = $this->opa_element_info) { $vn_x = $pn_x + $this->opo_form->getValueInPoints($va_element_info['left']); $vn_y = $pn_y - $this->opo_form->getValueInPoints($va_element_info['top']); } break; default: $this->opo_form->postError(2275, _t("Invalid class '%1'", get_class($this->opo_form)), "PrintFormBarcodeElement->render()"); break; } $va_style = $this->opo_form->getStyle($va_element_info['style']); $vn_w = $this->opo_form->getValueInPoints($va_element_info['width']); $vn_h = $this->opo_form->getValueInPoints($va_element_info['height']); $o_barcode = new Barcode(); if (!isset($va_element_info['barcode'])) { $va_element_info['barcode'] = $va_style['barcode']; } $vs_tmp = tempnam('/tmp', 'caBarCode'); $va_dimensions = $o_barcode->draw($this->getValue(), $vs_tmp . '.png', isset($va_element_info['barcode']) ? $va_element_info['barcode'] : 'code128', 'png', $vn_h); $vn_image_width = $va_dimensions['width']; $vn_image_height = $va_dimensions['height']; if (!$vn_image_width || !$vn_image_height) { return false; } if ($vn_image_width / $vn_w > $vn_image_height / $vn_h) { $vn_r = $vn_w / $vn_image_width; } else { $vn_r = $vn_h / $vn_image_height; } $vn_image_width *= $vn_r; $vn_image_height *= $vn_r; if ($this->opo_form->getPDFLibrary() == __PDF_LIBRARY_ZEND__) { if ($vn_image_ref = $this->opo_form->loadImage($po_pdf, $vs_tmp . '.png')) { $po_pdf->pages[sizeof($po_pdf->pages) - 1]->drawImage($vn_image_ref, $vn_x, $vn_y - $vn_h, $vn_x + $vn_image_width, $vn_y - $vn_h + $vn_image_height); } } else { if ($vn_image_ref = $this->opo_form->loadImage($po_pdf, $vs_tmp . '.png')) { if (!($vs_display = $va_element_info['display'])) { $vs_display = $va_style['display']; } if (!in_array($vs_display, array('nofit', 'clip', 'meet', 'auto', 'slice', 'entire'))) { $vs_display = 'meet'; } $vs_opts = "fitmethod={$vs_display} boxsize={" . $vn_image_width . " " . $vn_image_height . "}"; if ($va_element_info['rotate']) { $vs_opts .= ' rotate=' . intval($va_element_info['rotate']); } else { if ($va_style['rotate']) { $vs_opts .= ' rotate=' . intval($va_style['rotate']); } } $po_pdf->fit_image($vn_image_ref, $vn_x, $vn_y - $vn_h, $vs_opts); } } @unlink($vs_tmp); @unlink($vs_tmp . '.png'); return true; }