diff --git a/lib/Bridge/ImageParametersDTO.php b/lib/Bridge/ImageParametersDTO.php index 15635151..04c7bdbd 100644 --- a/lib/Bridge/ImageParametersDTO.php +++ b/lib/Bridge/ImageParametersDTO.php @@ -27,12 +27,22 @@ class ImageParametersDTO 'type' => TType::STRUCT, 'class' => '\Aspose\Barcode\Bridge\SvgParametersDTO', ), + 2 => array( + 'var' => 'pdf', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Aspose\Barcode\Bridge\PdfParametersDTO', + ), ); /** * @var \Aspose\Barcode\Bridge\SvgParametersDTO */ public $svg = null; + /** + * @var \Aspose\Barcode\Bridge\PdfParametersDTO + */ + public $pdf = null; public function __construct($vals = null) { @@ -40,6 +50,9 @@ public function __construct($vals = null) if (isset($vals['svg'])) { $this->svg = $vals['svg']; } + if (isset($vals['pdf'])) { + $this->pdf = $vals['pdf']; + } } } @@ -70,6 +83,14 @@ public function read($input) $xfer += $input->skip($ftype); } break; + case 2: + if ($ftype == TType::STRUCT) { + $this->pdf = new \Aspose\Barcode\Bridge\PdfParametersDTO(); + $xfer += $this->pdf->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; default: $xfer += $input->skip($ftype); break; @@ -92,6 +113,14 @@ public function write($output) $xfer += $this->svg->write($output); $xfer += $output->writeFieldEnd(); } + if ($this->pdf !== null) { + if (!is_object($this->pdf)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('pdf', TType::STRUCT, 2); + $xfer += $this->pdf->write($output); + $xfer += $output->writeFieldEnd(); + } $xfer += $output->writeFieldStop(); $xfer += $output->writeStructEnd(); return $xfer; diff --git a/lib/Bridge/PdfParametersDTO.php b/lib/Bridge/PdfParametersDTO.php new file mode 100644 index 00000000..4db08942 --- /dev/null +++ b/lib/Bridge/PdfParametersDTO.php @@ -0,0 +1,214 @@ + array( + 'var' => 'cmykBarColor', + 'isRequired' => false, + 'type' => TType::STRING, + ), + 2 => array( + 'var' => 'cmykBackColor', + 'isRequired' => false, + 'type' => TType::STRING, + ), + 3 => array( + 'var' => 'cmykCodetextColor', + 'isRequired' => false, + 'type' => TType::STRING, + ), + 4 => array( + 'var' => 'cmykCaptionAboveColor', + 'isRequired' => false, + 'type' => TType::STRING, + ), + 5 => array( + 'var' => 'cmykCaptionBelowColor', + 'isRequired' => false, + 'type' => TType::STRING, + ), + 6 => array( + 'var' => 'textAsPath', + 'isRequired' => false, + 'type' => TType::BOOL, + ), + ); + + /** + * @var string + */ + public $cmykBarColor = null; + /** + * @var string + */ + public $cmykBackColor = null; + /** + * @var string + */ + public $cmykCodetextColor = null; + /** + * @var string + */ + public $cmykCaptionAboveColor = null; + /** + * @var string + */ + public $cmykCaptionBelowColor = null; + /** + * @var bool + */ + public $textAsPath = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['cmykBarColor'])) { + $this->cmykBarColor = $vals['cmykBarColor']; + } + if (isset($vals['cmykBackColor'])) { + $this->cmykBackColor = $vals['cmykBackColor']; + } + if (isset($vals['cmykCodetextColor'])) { + $this->cmykCodetextColor = $vals['cmykCodetextColor']; + } + if (isset($vals['cmykCaptionAboveColor'])) { + $this->cmykCaptionAboveColor = $vals['cmykCaptionAboveColor']; + } + if (isset($vals['cmykCaptionBelowColor'])) { + $this->cmykCaptionBelowColor = $vals['cmykCaptionBelowColor']; + } + if (isset($vals['textAsPath'])) { + $this->textAsPath = $vals['textAsPath']; + } + } + } + + public function getName() + { + return 'PdfParametersDTO'; + } + + + public function read($input) + { + $xfer = 0; + $fname = null; + $ftype = 0; + $fid = 0; + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) { + case 1: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->cmykBarColor); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->cmykBackColor); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->cmykCodetextColor); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->cmykCaptionAboveColor); + } else { + $xfer += $input->skip($ftype); + } + break; + case 5: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->cmykCaptionBelowColor); + } else { + $xfer += $input->skip($ftype); + } + break; + case 6: + if ($ftype == TType::BOOL) { + $xfer += $input->readBool($this->textAsPath); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $xfer = 0; + $xfer += $output->writeStructBegin('PdfParametersDTO'); + if ($this->cmykBarColor !== null) { + $xfer += $output->writeFieldBegin('cmykBarColor', TType::STRING, 1); + $xfer += $output->writeString($this->cmykBarColor); + $xfer += $output->writeFieldEnd(); + } + if ($this->cmykBackColor !== null) { + $xfer += $output->writeFieldBegin('cmykBackColor', TType::STRING, 2); + $xfer += $output->writeString($this->cmykBackColor); + $xfer += $output->writeFieldEnd(); + } + if ($this->cmykCodetextColor !== null) { + $xfer += $output->writeFieldBegin('cmykCodetextColor', TType::STRING, 3); + $xfer += $output->writeString($this->cmykCodetextColor); + $xfer += $output->writeFieldEnd(); + } + if ($this->cmykCaptionAboveColor !== null) { + $xfer += $output->writeFieldBegin('cmykCaptionAboveColor', TType::STRING, 4); + $xfer += $output->writeString($this->cmykCaptionAboveColor); + $xfer += $output->writeFieldEnd(); + } + if ($this->cmykCaptionBelowColor !== null) { + $xfer += $output->writeFieldBegin('cmykCaptionBelowColor', TType::STRING, 5); + $xfer += $output->writeString($this->cmykCaptionBelowColor); + $xfer += $output->writeFieldEnd(); + } + if ($this->textAsPath !== null) { + $xfer += $output->writeFieldBegin('textAsPath', TType::BOOL, 6); + $xfer += $output->writeBool($this->textAsPath); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/lib/Bridge/ThriftAsposeBarcodeServiceClient.php b/lib/Bridge/ThriftAsposeBarcodeServiceClient.php index 7132df58..b91af292 100644 --- a/lib/Bridge/ThriftAsposeBarcodeServiceClient.php +++ b/lib/Bridge/ThriftAsposeBarcodeServiceClient.php @@ -1096,6 +1096,9 @@ public function recv_BarcodeGenerator_generateBarCodeImage() if ($result->success !== null) { return $result->success; } + if ($result->ex !== null) { + throw $result->ex; + } throw new \Exception("BarcodeGenerator_generateBarCodeImage failed: unknown result"); } @@ -1155,6 +1158,9 @@ public function recv_BarcodeGenerator_importFromXml() if ($result->success !== null) { return $result->success; } + if ($result->ex !== null) { + throw $result->ex; + } throw new \Exception("BarcodeGenerator_importFromXml failed: unknown result"); } @@ -1214,6 +1220,9 @@ public function recv_BarcodeGenerator_exportToXml() if ($result->success !== null) { return $result->success; } + if ($result->ex !== null) { + throw $result->ex; + } throw new \Exception("BarcodeGenerator_exportToXml failed: unknown result"); } diff --git a/lib/Bridge/ThriftAsposeBarcodeServiceIf.php b/lib/Bridge/ThriftAsposeBarcodeServiceIf.php index fe941652..5fb3eadb 100644 --- a/lib/Bridge/ThriftAsposeBarcodeServiceIf.php +++ b/lib/Bridge/ThriftAsposeBarcodeServiceIf.php @@ -111,16 +111,19 @@ public function BarcodeGenerator_ctor($encodeType); * @param int $imageFormat * @param string $base64LicenseContent * @return string + * @throws \Aspose\Barcode\Bridge\BarcodeExceptionDTO */ public function BarcodeGenerator_generateBarCodeImage(\Aspose\Barcode\Bridge\BarcodeGeneratorDTO $barcodeGeneratorDTO, $imageFormat, $base64LicenseContent); /** * @param string $source * @return \Aspose\Barcode\Bridge\BarcodeGeneratorDTO + * @throws \Aspose\Barcode\Bridge\BarcodeExceptionDTO */ public function BarcodeGenerator_importFromXml($source); /** * @param \Aspose\Barcode\Bridge\BarcodeGeneratorDTO $barcodeGeneratorDTO * @return string + * @throws \Aspose\Barcode\Bridge\BarcodeExceptionDTO */ public function BarcodeGenerator_exportToXml(\Aspose\Barcode\Bridge\BarcodeGeneratorDTO $barcodeGeneratorDTO); /** diff --git a/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_exportToXml_result.php b/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_exportToXml_result.php index cfdee3ac..07e2aeaf 100644 --- a/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_exportToXml_result.php +++ b/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_exportToXml_result.php @@ -26,12 +26,22 @@ class ThriftAsposeBarcodeService_BarcodeGenerator_exportToXml_result 'isRequired' => false, 'type' => TType::STRING, ), + 1 => array( + 'var' => 'ex', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Aspose\Barcode\Bridge\BarcodeExceptionDTO', + ), ); /** * @var string */ public $success = null; + /** + * @var \Aspose\Barcode\Bridge\BarcodeExceptionDTO + */ + public $ex = null; public function __construct($vals = null) { @@ -39,6 +49,9 @@ public function __construct($vals = null) if (isset($vals['success'])) { $this->success = $vals['success']; } + if (isset($vals['ex'])) { + $this->ex = $vals['ex']; + } } } @@ -68,6 +81,14 @@ public function read($input) $xfer += $input->skip($ftype); } break; + case 1: + if ($ftype == TType::STRUCT) { + $this->ex = new \Aspose\Barcode\Bridge\BarcodeExceptionDTO(); + $xfer += $this->ex->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; default: $xfer += $input->skip($ftype); break; @@ -87,6 +108,11 @@ public function write($output) $xfer += $output->writeString($this->success); $xfer += $output->writeFieldEnd(); } + if ($this->ex !== null) { + $xfer += $output->writeFieldBegin('ex', TType::STRUCT, 1); + $xfer += $this->ex->write($output); + $xfer += $output->writeFieldEnd(); + } $xfer += $output->writeFieldStop(); $xfer += $output->writeStructEnd(); return $xfer; diff --git a/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_generateBarCodeImage_result.php b/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_generateBarCodeImage_result.php index d9c27eeb..45d20297 100644 --- a/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_generateBarCodeImage_result.php +++ b/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_generateBarCodeImage_result.php @@ -26,12 +26,22 @@ class ThriftAsposeBarcodeService_BarcodeGenerator_generateBarCodeImage_result 'isRequired' => false, 'type' => TType::STRING, ), + 1 => array( + 'var' => 'ex', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Aspose\Barcode\Bridge\BarcodeExceptionDTO', + ), ); /** * @var string */ public $success = null; + /** + * @var \Aspose\Barcode\Bridge\BarcodeExceptionDTO + */ + public $ex = null; public function __construct($vals = null) { @@ -39,6 +49,9 @@ public function __construct($vals = null) if (isset($vals['success'])) { $this->success = $vals['success']; } + if (isset($vals['ex'])) { + $this->ex = $vals['ex']; + } } } @@ -68,6 +81,14 @@ public function read($input) $xfer += $input->skip($ftype); } break; + case 1: + if ($ftype == TType::STRUCT) { + $this->ex = new \Aspose\Barcode\Bridge\BarcodeExceptionDTO(); + $xfer += $this->ex->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; default: $xfer += $input->skip($ftype); break; @@ -87,6 +108,11 @@ public function write($output) $xfer += $output->writeString($this->success); $xfer += $output->writeFieldEnd(); } + if ($this->ex !== null) { + $xfer += $output->writeFieldBegin('ex', TType::STRUCT, 1); + $xfer += $this->ex->write($output); + $xfer += $output->writeFieldEnd(); + } $xfer += $output->writeFieldStop(); $xfer += $output->writeStructEnd(); return $xfer; diff --git a/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_importFromXml_result.php b/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_importFromXml_result.php index 7d64a892..72fe30f6 100644 --- a/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_importFromXml_result.php +++ b/lib/Bridge/ThriftAsposeBarcodeService_BarcodeGenerator_importFromXml_result.php @@ -27,12 +27,22 @@ class ThriftAsposeBarcodeService_BarcodeGenerator_importFromXml_result 'type' => TType::STRUCT, 'class' => '\Aspose\Barcode\Bridge\BarcodeGeneratorDTO', ), + 1 => array( + 'var' => 'ex', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Aspose\Barcode\Bridge\BarcodeExceptionDTO', + ), ); /** * @var \Aspose\Barcode\Bridge\BarcodeGeneratorDTO */ public $success = null; + /** + * @var \Aspose\Barcode\Bridge\BarcodeExceptionDTO + */ + public $ex = null; public function __construct($vals = null) { @@ -40,6 +50,9 @@ public function __construct($vals = null) if (isset($vals['success'])) { $this->success = $vals['success']; } + if (isset($vals['ex'])) { + $this->ex = $vals['ex']; + } } } @@ -70,6 +83,14 @@ public function read($input) $xfer += $input->skip($ftype); } break; + case 1: + if ($ftype == TType::STRUCT) { + $this->ex = new \Aspose\Barcode\Bridge\BarcodeExceptionDTO(); + $xfer += $this->ex->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; default: $xfer += $input->skip($ftype); break; @@ -92,6 +113,11 @@ public function write($output) $xfer += $this->success->write($output); $xfer += $output->writeFieldEnd(); } + if ($this->ex !== null) { + $xfer += $output->writeFieldBegin('ex', TType::STRUCT, 1); + $xfer += $this->ex->write($output); + $xfer += $output->writeFieldEnd(); + } $xfer += $output->writeFieldStop(); $xfer += $output->writeStructEnd(); return $xfer; diff --git a/lib/Generation.php b/lib/Generation.php index 4263ba62..205f2b35 100644 --- a/lib/Generation.php +++ b/lib/Generation.php @@ -1,6 +1,7 @@ BarcodeGenerator_generateBarCodeImage($this->getBarcodeGeneratorDto(), $format, $licenseContent); $thriftConnection->closeConnection(); return $base64Image; - } catch (Exception $exc) { + }catch (BarcodeExceptionDTO $be) { + $msg = $be->message ?? '(no message)'; + $pos = $be->position ?? ''; + $kind = $be->kind ?? ''; + // pass a clear message up so it gets into your report + throw new \Exception("Java error" . + ($kind !== null ? " [$kind]" : "") . + ": $msg\n$pos"); + } + + catch (Exception $exc) { throw new BarcodeException($exc->getMessage(), __FILE__, __LINE__); } } @@ -7134,6 +7146,251 @@ function getSvgColorMode() : int } } +/** + * PDF parameters wrapper. + * Expects an underlying `javaClass` instance that provides + * the corresponding getter/setter methods returning/accepting + * CMYK strings like "30_100_0_30" or `null`. + */ +class PdfParameters implements Communicator +{ + private $pdfParametersDto; + + function getPdfParametersDto(): PdfParametersDTO + { + return $this->pdfParametersDto; + } + + private function setPdfParametersDto(PdfParametersDTO $pdfParametersDto): void + { + $this->pdfParametersDto = $pdfParametersDto; + } + + function __construct(PdfParametersDTO $pdfParametersDto) + { + $this->pdfParametersDto = $pdfParametersDto; + $this->obtainDto(); + $this->initFieldsFromDto(); + } + + public function obtainDto(...$args) + { + } + + public function initFieldsFromDto(): void + { + } + /** + *

+ * Nullable. CMYK color value of bar code. Null means CMYK color is not used, instead normal RGB color is used. + *

+ */ + function getCMYKBarColor() : CMYKColor + { + return CMYKColor::parseCMYK($this->getPdfParametersDto()->cmykBarColor); + } + /** + *

+ * Nullable. CMYK color value of bar code. Null means CMYK color is not used, instead normal RGB color is used. + *

+ */ + function setCMYKBarColor(CMYKColor $value) : void + { + $this->getPdfParametersDto()->cmykBarColor = $value != null ? $value->formatCMYK() : null; + } + + /** + *

+ * Nullable. CMYK back color value. Null means CMYK color is not used, instead normal RGB color is used. + *

+ */ + public function getCMYKBackColor() : CMYKColor + { + return CMYKColor::parseCMYK($this->getPdfParametersDto()->cmykBackColor); + } + /** + *

+ * Nullable. CMYK back color value. Null means CMYK color is not used, instead normal RGB color is used. + *

+ */ + public function setCMYKBackColor(CMYKColor $value) : void + { + $this->getPdfParametersDto()->cmykBackColor = ($value != null ? $value->formatCMYK() : null); + } + + /** + *

+ * Nullable. CMYK color value of Codetext. Null means CMYK color is not used, instead normal RGB color is used. + *

+ */ + public function getCMYKCodetextColor() : CMYKColor + { + return CMYKColor::parseCMYK($this->getPdfParametersDto()->cmykCodetextColor); + } + + /** + *

+ * Nullable. CMYK color value of Codetext. Null means CMYK color is not used, instead normal RGB color is used. + *

+ */ + public function setCMYKCodetextColor(CMYKColor $value) : void + { + $this->getPdfParametersDto()->cmykCodetextColor = $value != null ? $value->formatCMYK() : null; + } + + /** + *

+ * Nullable. CMYK color value of caption above. Null means CMYK color is not used, instead normal RGB color is used. + *

+ */ + public function getCMYKCaptionAboveColor() : CMYKColor + { + return CMYKColor::parseCMYK($this->getPdfParametersDto()->cmykCaptionAboveColor); + } + /** + *

+ * Nullable. CMYK color value of caption above. Null means CMYK color is not used, instead normal RGB color is used. + *

+ */ + public function setCMYKCaptionAboveColor(CMYKColor $value) : void + { + $this->getPdfParametersDto()->cmykCaptionAboveColor = $value != null ? $value->formatCMYK() : null; + } + + /** + *

+ * Nullable. CMYK color value of caption below. Null means CMYK color is not used, instead normal RGB color is used. + *

+ */ + public function getCMYKCaptionBelowColor() : CMYKColor + { + return CMYKColor::parseCMYK($this->getPdfParametersDto()->cmykCaptionBelowColor); + } + /** + *

+ * Nullable. CMYK color value of caption below. Null means CMYK color is not used, instead normal RGB color is used. + *

+ */ + public function setCMYKCaptionBelowColor(CMYKColor $value) : void + { + $this->getPdfParametersDto()->cmykCaptionBelowColor = $value->formatCMYK(); + } + + /** + *

+ * Are paths used instead of text (use if Unicode characters are not displayed) + * Default value: false. + *

+ */ + public function isTextAsPath() : bool + { + return $this->getPdfParametersDto()->textAsPath; + } + + /** + *

+ * Are paths used instead of text (use if Unicode characters are not displayed) + * Default value: false. + *

+ */ + public function setTextAsPath(bool $value) : void + { + $this->getPdfParametersDto()->textAsPath = $value; + } +} + +/** + * Class for CMYK color. A null instance means CMYK is not used, + * and default RGB color is in use. + */ +class CMYKColor +{ + /** @var float Cyan component (0.0–1.0) */ + public float $C; + + /** @var float Magenta component (0.0–1.0) */ + public float $M; + + /** @var float Yellow component (0.0–1.0) */ + public float $Y; + + /** @var float Black component (0.0–1.0) */ + public float $K; + + /** + * Initializes a new instance of the CMYKColor class from CMYK values. + * CMYK values are expected in the range 0–100. + * + * @param int $c Cyan value [0, 100] + * @param int $m Magenta value [0, 100] + * @param int $y Yellow value [0, 100] + * @param int $k Black value [0, 100] + */ + public function __construct(int $c,int $m,int $y,int $k) + { + // Clamp to [0, 100] and store as fractions [0.0, 1.0] + $this->C = min(100, max(0, $c)) / 100.0; + $this->M = min(100, max(0, $m)) / 100.0; + $this->Y = min(100, max(0, $y)) / 100.0; + $this->K = min(100, max(0, $k)) / 100.0; + } + + /** + * Parse a CMYK string of the form "C_M_Y_K" into a CMYKColor instance. + * + * @param string $str a string like "30_100_0_30" + * @return CMYKColor + * @throws InvalidArgumentException if the format is invalid or values are not numeric + */ + public static function parseCMYK(string $str): CMYKColor + { + $parts = explode('_', $str); + if (count($parts) !== 4) { + throw new InvalidArgumentException("Invalid CMYK string: expected 4 parts but got " . count($parts)); + } + + $nums = []; + foreach ($parts as $i => $s) { + if (!is_numeric($s)) { + throw new InvalidArgumentException("Invalid number in CMYK string at index $i: \"$s\""); + } + // PHP does not auto-convert to float in this context + $nums[] = floatval($s); + } + + return new CMYKColor($nums[0], $nums[1], $nums[2], $nums[3]); + } + + /** + * Format this CMYKColor into a string "C_M_Y_K", + * multiplying each internal component (0–1) by 100 and rounding. + * + * @return string e.g. "30_100_0_30" + */ + public function formatCMYK(): string + { + $c = round($this->C * 100); + $m = round($this->M * 100); + $y = round($this->Y * 100); + $k = round($this->K * 100); + return "{$c}_{$m}_{$y}_{$k}"; + } + + /** + * Optional: a human-readable representation. + * + * @return string + */ + public function __toString(): string + { + $c = round($this->C * 100); + $m = round($this->M * 100); + $y = round($this->Y * 100); + $k = round($this->K * 100); + return "CMYKColor(C={$c}%, M={$m}%, Y={$y}%, K={$k}%)"; + } +} + /** *

* Class for representing HSLA color (Hue, Saturation, Lightness, Alpha) @@ -8064,24 +8321,24 @@ class BorderDashStyle /** * Specifies a solid line. */ - const SOLID = "0"; //DashStyle.Solid + const SOLID = 0; //DashStyle.Solid /** * Specifies a line consisting of dashes. */ - const DASH = "1"; // DashStyle.Dash + const DASH = 1; // DashStyle.Dash /** * Specifies a line consisting of dots. */ - const DOT = "2"; //(DashStyle.Dot + const DOT = 2; //(DashStyle.Dot /** * Specifies a line consisting of a repeating pattern of dash-dot. */ - const DASH_DOT = "3"; //DashStyle.DashDot + const DASH_DOT = 3; //DashStyle.DashDot /** * Specifies a line consisting of a repeating pattern of dash-dot-dot. */ - const DASH_DOT_DOT = "4"; //DashStyle.DashDotDot + const DASH_DOT_DOT = 4; //DashStyle.DashDotDot } /** diff --git a/lib/Internal/CommonUtility.php b/lib/Internal/CommonUtility.php index 2baa5ecf..4ff05243 100644 --- a/lib/Internal/CommonUtility.php +++ b/lib/Internal/CommonUtility.php @@ -120,52 +120,52 @@ public static function convertAreasToStringFormattedAreas($areas): array public static function convertImageResourceToBase64($imageResource): ?string { - if (is_null($imageResource)) { + if ($imageResource === null) { return null; } - // Handle resource types + // Handle GD resource if (is_resource($imageResource)) { $type = get_resource_type($imageResource); - if ($type === 'gd') { - ob_start(); - imagepng($imageResource); - $imageData = ob_get_contents(); - ob_end_clean(); - return base64_encode($imageData); - } + switch ($type) { + case 'gd': + ob_start(); + imagepng($imageResource); + $imageData = ob_get_clean(); // same as ob_get_contents() + ob_end_clean() + return base64_encode($imageData); - if ($type === 'file') { - $imageData = stream_get_contents($imageResource); - fclose($imageResource); - return base64_encode($imageData); - } + case 'file': + $imageData = stream_get_contents($imageResource); + fclose($imageResource); + return base64_encode($imageData); - throw new BarcodeException("This resource type is not supported: " . $type); + default: + throw new BarcodeException("Unsupported resource type: $type"); + } } + // Handle string input if (is_string($imageResource)) { - // Check if it's already a valid base64 string - if (base64_encode(base64_decode($imageResource, true)) === $imageResource) { - return $imageResource; - } - // Check if it's a valid file path - if (is_file($imageResource)) { + // If string is a valid file path + if (file_exists($imageResource) && is_file($imageResource) && is_readable($imageResource)) { $fileContent = file_get_contents($imageResource); + if ($fileContent === false) { + throw new BarcodeException("Failed to read file content: $imageResource"); + } return base64_encode($fileContent); } - // If it's a string but file does not exist - if (!file_exists($imageResource)) { - throw new BarcodeException("File does not exist: " . $imageResource); + + // If string is already valid base64 (safe check) + if (base64_encode(base64_decode($imageResource, true)) === $imageResource) { + return $imageResource; } + throw new BarcodeException("File does not exist or is not readable: $imageResource"); } + // Unsupported input throw new BarcodeException("Unsupported input type. Expected GD resource, file resource, base64 string, or valid file path."); } - - -} - +} \ No newline at end of file diff --git a/lib/Recognition.php b/lib/Recognition.php index 011bd0ca..1f79f553 100644 --- a/lib/Recognition.php +++ b/lib/Recognition.php @@ -299,8 +299,6 @@ public function getFoundCount(): int * //set high performance mode * $reader->setQualitySettings(QualitySettings::getHighPerformance()); * //set separate options - * $reader->getQualitySettings()->setAllowMedianSmoothing(true); - * $reader->getQualitySettings()->setMedianSmoothingWindowSize(5); * foreach($reader->readBarCodes() as $result) * print("BarCode CodeText: ".$result->getCodeText()); * @@ -332,8 +330,6 @@ public final function getQualitySettings(): QualitySettings * //set high performance mode * $reader->setQualitySettings(QualitySettings::getHighPerformance()); * //set separate options - * $reader->getQualitySettings()->setAllowMedianSmoothing(true); - * $reader->getQualitySettings()->setMedianSmoothingWindowSize(5); * foreach($reader->readBarCodes() as $result) * print("BarCode CodeText: ".$result->getCodeText()); * @@ -380,7 +376,7 @@ public final function setBarCodeImage($imageResource, ?Rectangle ...$areas): voi { try { $this->barCodeReaderDto->base64Image = CommonUtility::convertImageResourceToBase64($imageResource); - $this->barCodeReaderDto->areas = CommonUtility::convertImageResourceToBase64($areas); + $this->barCodeReaderDto->areas = CommonUtility::convertAreasToStringFormattedAreas($areas); if(is_null($this->barCodeReaderDto->barCodeDecodeTypes) || sizeof($this->barCodeReaderDto->barCodeDecodeTypes) == 0) $this->barCodeReaderDto->barCodeDecodeTypes = array(DecodeType::ALL_SUPPORTED_TYPES); } catch (Exception $ex) { @@ -849,15 +845,11 @@ public function setIgnoreEndingFillingPatternsForCTable(bool $value): void * //set high performance mode * $reader->setQualitySettings(QualitySettings::getHighPerformance()); * //set separate options - * $reader->getQualitySettings()->setAllowMedianSmoothing(true); - * $reader->getQualitySettings()->setMedianSmoothingWindowSize(5); * foreach($reader->readBarCodes() as $result) * print("BarCode CodeText: ".$result->getCodeText()); * $reader = new BarCodeReader("test.png", null, array(DecodeType::CODE_39, DecodeType::CODE_128)); * //default mode is NormalQuality * //set separate options - * $reader->getQualitySettings()->setAllowMedianSmoothing(true); - * $reader->getQualitySettings()->setMedianSmoothingWindowSize(5); * foreach($reader->readBarCodes() as $result) * print("BarCode CodeText: ".$result->getCodeText()); * @endcode @@ -1205,7 +1197,7 @@ public function getReadingQuality(): float throw new BarcodeException($ex->getMessage(), __FILE__, __LINE__); } } - + /** *

* Gets the code text with encoding. @@ -2110,7 +2102,7 @@ private static function convertCode128DataPortions($javaCode128DataPortions): ar */ public function getCode128DataPortions(): array { - return $this->code128DataPortions; + return $this->code128DataPortions; } public function isEmpty(): bool @@ -2560,6 +2552,7 @@ public function toString(): string throw new BarcodeException($ex->getMessage(), __FILE__, __LINE__); } } + } diff --git a/lib/aspose-barcode-php-25.7.jar b/lib/aspose-barcode-php-25.8.jar similarity index 86% rename from lib/aspose-barcode-php-25.7.jar rename to lib/aspose-barcode-php-25.8.jar index ae82321f..cd5abcdd 100644 Binary files a/lib/aspose-barcode-php-25.7.jar and b/lib/aspose-barcode-php-25.8.jar differ