From c1010eda29c0909ed4d5d463f32d32bfefdd4dfe Mon Sep 17 00:00:00 2001 From: Greg Roach Date: Mon, 16 Jul 2018 08:20:33 +0100 Subject: Use PSR2 code style --- app/Report/ReportBase.php | 1148 ++++--- app/Report/ReportBaseCell.php | 327 +- app/Report/ReportBaseElement.php | 194 +- app/Report/ReportBaseFootnote.php | 214 +- app/Report/ReportBaseHtml.php | 99 +- app/Report/ReportBaseImage.php | 172 +- app/Report/ReportBaseLine.php | 124 +- app/Report/ReportBasePageheader.php | 58 +- app/Report/ReportBaseText.php | 130 +- app/Report/ReportBaseTextbox.php | 257 +- app/Report/ReportHtml.php | 1463 ++++----- app/Report/ReportHtmlCell.php | 336 ++- app/Report/ReportHtmlFootnote.php | 287 +- app/Report/ReportHtmlHtml.php | 90 +- app/Report/ReportHtmlImage.php | 125 +- app/Report/ReportHtmlLine.php | 66 +- app/Report/ReportHtmlPageheader.php | 26 +- app/Report/ReportHtmlText.php | 310 +- app/Report/ReportHtmlTextbox.php | 478 +-- app/Report/ReportParserBase.php | 142 +- app/Report/ReportParserGenerate.php | 5591 ++++++++++++++++++----------------- app/Report/ReportParserSetup.php | 231 +- app/Report/ReportPdf.php | 503 ++-- app/Report/ReportPdfCell.php | 242 +- app/Report/ReportPdfFootnote.php | 277 +- app/Report/ReportPdfHtml.php | 73 +- app/Report/ReportPdfImage.php | 188 +- app/Report/ReportPdfLine.php | 52 +- app/Report/ReportPdfPageheader.php | 26 +- app/Report/ReportPdfText.php | 298 +- app/Report/ReportPdfTextbox.php | 594 ++-- app/Report/ReportTcpdf.php | 775 ++--- 32 files changed, 7794 insertions(+), 7102 deletions(-) (limited to 'app/Report') diff --git a/app/Report/ReportBase.php b/app/Report/ReportBase.php index 92227852dd..96bfd8a9cc 100644 --- a/app/Report/ReportBase.php +++ b/app/Report/ReportBase.php @@ -20,456 +20,700 @@ use Fisharebest\Webtrees\I18N; /** * Class ReportBase */ -class ReportBase { - /** User measure unit. */ - const UNITS = 'pt'; - - /** webtrees URL */ - const WT_URL = WT_WEBTREES_URL; - - /** @var float Left Margin (expressed in points) Default: 17.99 mm, 0.7083 inch */ - public $leftmargin = 51.0; - - /** @var float Right Margin (expressed in points) Default: 9.87 mm, 0.389 inch */ - public $rightmargin = 28.0; - - /** @var float Top Margin (expressed in points) Default: 26.81 mm */ - public $topmargin = 76.0; - - /** @var float Bottom Margin (expressed in points) Default: 21.6 mm */ - public $bottommargin = 60.0; - - /** @var float Header Margin (expressed in points) Default: 4.93 mm */ - public $headermargin = 14.0; - - /** @var float Footer Margin (expressed in points) Default: 9.88 mm, 0.389 inch */ - public $footermargin = 28.0; - - /** @var string Page orientation (portrait, landscape) */ - public $orientation = 'portrait'; - - /** @var string Page format name */ - public $pageFormat = 'A4'; - - /** @var float Height of page format in points */ - public $pageh = 0.0; - - /** @var float Width of page format in points */ - public $pagew = 0.0; - - /** @var string[][] An array of the Styles elements found in the document */ - public $Styles = []; - - /** @var string The default Report font name */ - public $defaultFont = 'dejavusans'; - - /** @var int The default Report font size */ - public $defaultFontSize = 12; - - /** @var string Header (H), Page header (PH), Body (B) or Footer (F) */ - public $processing = 'H'; - - /** @var bool RTL Language (false=LTR, true=RTL) */ - public $rtl = false; - - /** @var bool Show the Generated by... (true=show the text) */ - public $showGenText = true; - - /** @var string Generated By... text */ - public $generatedby = ''; - - /** @var string The report title */ - public $title = ''; - - /** @var string Author of the report, the users full name */ - public $rauthor = WT_WEBTREES . ' ' . WT_VERSION; - - /** @var string Keywords */ - public $rkeywords = ''; - - /** @var string Report Description / Subject */ - public $rsubject = ''; - - /** - * Initial Setup - ReportBase - * - * Setting up document wide defaults that will be inherited of the report modules - * As DEFAULT A4 and Portrait will be used if not set - */ - public function setup() { - // Set RTL direction - if (I18N::direction() === 'rtl') { - $this->rtl = true; - } - // Set the Keywords - $this->rkeywords = ''; - // Generated By...text - // I18N: This is a report footer. %s is the name of the application. - $this->generatedby = I18N::translate('Generated by %s', WT_WEBTREES . ' ' . WT_VERSION); - - // For known size pages - if ($this->pagew == 0 && $this->pageh == 0) { - /** - * The current ISO 216 standard was introduced in 1975 and is a direct follow up to the german DIN 476 standard from 1922. ISO 216 is also called EN 20216 in Europe. - * The ISO paper sizes are based on the metric system so everything else is aproxiamte - * - * The Series A is used for Standard Printing and Stationary. - * The Series B is used for Posters, Wall-Charts etc. - * The C series is used for folders, post cards and envelopes. C series envelope is suitable to insert A series sizes. - * ISO also define format series RA and SRA for untrimmed raw paper, where SRA stands for 'supplementary raw format A'. - * Japan has adopted the ISO series A sizes, but its series B sizes are slightly different. These sizes are sometimes called JIS B or JB sizes. - * sun was a unit of length used in Japan and is equal to about 3.03 cm or 1.193 inches - * The United States, Canada, and in part Mexico, are today the only industrialized nations in which the ISO standard paper sizes are not yet widely used. - * - * A0 & A1 Technical drawings, posters - * A1 & A2 Flip charts - * A2 & A3 Drawings, diagrams, large tables - * A4 Letters, magazines, forms, catalogs, laser printer and copying machine output - * A5 Note pads - * A6 Postcards - * B5, A5, B6 A6 Books - * C4, C5, C6 Envelopes for A4 letters: unfolded (C4), folded once (C5), folded twice (C6) - * B4 & A3 Newspapers, supported by most copying machines in addition to A4 - * B8 & A8 Playing cards - * - * 1 inch = 72 points - * 1 mm = 2.8346457 points - * 1 inch = 25.4 mm - * 1 point = 0,35278 mm - */ - switch ($this->pageFormat) { - // ISO A series - case '4A0': // ISO 216, 1682 mm x 2378 mm - $sizes = [4767.86, 6740.79]; - break; - case '2A0': // ISO 216, 1189 mm x 1682 mm - $sizes = [3370.39, 4767.86]; - break; - case 'A0': // ISO 216, 841 mm x 1189mm - $sizes = [2383.94, 3370.39]; - break; - case 'A1': // ISO 216, 594 mm x 841 mm - $sizes = [1683.78, 2383.94]; - break; - case 'A2': // ISO 216, 420 mm x 594 mm - $sizes = [1190.55, 1683.78]; - break; - case 'A3': // ISO 216, 297 mm x 420 mm - $sizes = [841.89, 1190.55]; - break; - case 'A4': // ISO 216, 210 mm 297 mm - $sizes = [595.28, 841.89]; - break; - case 'A5': // ISO 216, 148 mm x 210 mm - $sizes = [419.53, 595.28]; - break; - case 'A6': // ISO 216, 105 mm x 148 mm - $sizes = [297.64, 419.53]; - break; - case 'A7': // ISO 216, 74 mm x 105 mm - $sizes = [209.76, 297.64]; - break; - case 'A8': // ISO 216, 52 mm x 74 mm - $sizes = [147.40, 209.76]; - break; - case 'A9': // ISO 216, 37 mm x 52 mm - $sizes = [104.88, 147.40]; - break; - case 'A10': // ISO 216, 26 mm x 37 mm - $sizes = [73.70, 104.88]; - break; - - // ISO B series - case 'B0': // ISO 216, 1000 mm x 1414 mm - $sizes = [2834.65, 4008.19]; - break; - case 'B1': // ISO 216, 707 mm x 1000 mm - $sizes = [2004.09, 2834.65]; - break; - case 'B2': // ISO 216, 500 mm x 707 mm - $sizes = [1417.32, 2004.09]; - break; - case 'B3': // ISO 216, 353 mm x 500 mm - $sizes = [1000.63, 1417.32]; - break; - case 'B4': // ISO 216, 250 mm x 353 mm - $sizes = [708.66, 1000.63]; - break; - case 'B5': // ISO 216, 176 mm x 250 mm - $sizes = [498.90, 708.66]; - break; - case 'B6': // ISO 216, 125 mm x 176 mm - $sizes = [354.33, 498.90]; - break; - case 'B7': // ISO 216, 88 mm x 125 mm - $sizes = [249.45, 354.33]; - break; - case 'B8': // ISO 216, 62 mm x 88 mm - $sizes = [175.75, 249.45]; - break; - case 'B9': // ISO 216, 44 mm x 62 mm - $sizes = [124.72, 175.75]; - break; - case 'B10': // ISO 216, 31 mm x 44 mm - $sizes = [87.87, 124.72]; - break; - - // ISO C series, Envelope - case 'C0': // ISO 269, 917 mm x 1297 mm, For flat A0 sheet - $sizes = [2599.37, 3676.54]; - break; - case 'C1': // ISO 269, 648 mm x 917 mm, For flat A1 sheet - $sizes = [1836.85, 2599.37]; - break; - case 'C2': // ISO 269, 458 mm x 648 mm, For flat A2 sheet, A1 folded in half - $sizes = [1298.27, 1836.85]; - break; - case 'C3': // ISO 269, 324 mm x 458 mm, For flat A3 sheet, A2 folded in half - $sizes = [918.43, 1298.27]; - break; - case 'C4': // ISO 269, 229 mm x 324 mm, For flat A4 sheet, A3 folded in half - $sizes = [649.13, 918.43]; - break; - case 'C5': // ISO 269, 162 mm x 229 mm, For flat A5 sheet, A4 folded in half - $sizes = [459.21, 649.13]; - break; - case 'C6/5': // ISO 269, 114 mm x 229 mm. A5 folded twice = 1/3 A4. Alternative for the DL envelope - $sizes = [323.15, 649.13]; - break; - case 'C6': // ISO 269, 114 mm x 162 mm, For A5 folded in half - $sizes = [323.15, 459.21]; - break; - case 'C7/6': // ISO 269, 81 mm x 162 mm, For A5 sheet folded in thirds - $sizes = [229.61, 459.21]; - break; - case 'C7': // ISO 269, 81 mm x 114 mm, For A5 folded in quarters - $sizes = [229.61, 323.15]; - break; - case 'C8': // ISO 269, 57 mm x 81 mm - $sizes = [161.57, 229.61]; - break; - case 'C9': // ISO 269, 40 mm x 57 mm - $sizes = [113.39, 161.57]; - break; - case 'C10': // ISO 269, 28 mm x 40 mm - $sizes = [79.37, 113.39]; - break; - case 'DL': // Original DIN 678 but ISO 269 now has this C6/5 , 110 mm x 220 mm, For A4 sheet folded in thirds, A5 in half - $sizes = [311.81, 623.62]; - break; - - // Untrimmed stock sizes for the ISO-A Series - ISO primary range - case 'RA0': // ISO 478, 860 mm x 1220 mm - $sizes = [2437.80, 3458.27]; - break; - case 'RA1': // ISO 478, 610 mm x 860 mm - $sizes = [1729.13, 2437.80]; - break; - case 'RA2': // ISO 478, 430 mm x 610 mm - $sizes = [1218.90, 1729.13]; - break; - case 'RA3': // ISO 478, 305 mm x 430 mm - $sizes = [864.57, 1218.90]; - break; - case 'RA4': // ISO 478, 215 mm x 305 mm - $sizes = [609.45, 864.57]; - break; - - // Untrimmed stock sizes for the ISO-A Series - ISO supplementary range - case 'SRA0': // ISO 593, 900 mm x 1280 mm - $sizes = [2551.18, 3628.35]; - break; - case 'SRA1': // ISO 593, 640 mm x 900 mm - $sizes = [1814.17, 2551.18]; - break; - case 'SRA2': // ISO 593, 450 mm x 640 mm - $sizes = [1275.59, 1814.17]; - break; - case 'SRA3': // ISO 593, 320 mm x 450 mm - $sizes = [907.09, 1275.59]; - break; - case 'SRA4': // ISO 593, 225 mm x 320 mm - $sizes = [637.80, 907.09]; - break; - - // ISO size variations - case 'A2EXTRA': // ISO 216, 445 mm x 619 mm - $sizes = [1261.42, 1754.65]; - break; - case 'A2SUPER': // ISO 216, 305 mm x 508 mm - $sizes = [864.57, 1440.00]; - break; - case 'A3EXTRA': // ISO 216, 322 mm x 445 mm - $sizes = [912.76, 1261.42]; - break; - case 'SUPERA3': // ISO 216, 305 mm x 487 mm - $sizes = [864.57, 1380.47]; - break; - case 'A4EXTRA': // ISO 216, 235 mm x 322 mm - $sizes = [666.14, 912.76]; - break; - case 'A4LONG': // ISO 216, 210 mm x 348 mm - $sizes = [595.28, 986.46]; - break; - case 'A4SUPER': // ISO 216, 229 mm x 322 mm - $sizes = [649.13, 912.76]; - break; - case 'SUPERA4': // ISO 216, 227 mm x 356 mm - $sizes = [643.46, 1009.13]; - break; - case 'A5EXTRA': // ISO 216, 173 mm x 235 mm - $sizes = [490.39, 666.14]; - break; - case 'SOB5EXTRA': // ISO 216, 202 mm x 276 mm - $sizes = [572.60, 782.36]; - break; - - // Japanese version of the ISO 216 B series - case 'JB0': // JIS P 0138-61, 1030 mm x 1456 mm - $sizes = [2919.69, 4127.24]; - break; - case 'JB1': // JIS P 0138-61, 728 mm x 1030 mm - $sizes = [2063.62, 2919.69]; - break; - case 'JB2': // JIS P 0138-61, 515 mm x 728 mm - $sizes = [1459.84, 2063.62]; - break; - case 'JB3': // JIS P 0138-61, 364 mm x 515 mm - $sizes = [1031.81, 1459.84]; - break; - case 'JB4': // JIS P 0138-61, 257 mm x 364 mm - $sizes = [728.50, 1031.81]; - break; - case 'JB5': // JIS P 0138-61, 182 mm x 257 mm - $sizes = [515.91, 728.50]; - break; - case 'JB6': // JIS P 0138-61, 128 mm x 182 mm - $sizes = [362.83, 515.91]; - break; - case 'JB7': // JIS P 0138-61, 91 mm x 128 mm - $sizes = [257.95, 362.83]; - break; - case 'JB8': // JIS P 0138-61, 64 mm x 91 mm - $sizes = [181.42, 257.95]; - break; - case 'JB9': // JIS P 0138-61, 45 mm x 64 mm - $sizes = [127.56, 181.42]; - break; - case 'JB10': // JIS P 0138-61, 32 mm x 45 mm - $sizes = [90.71, 127.56]; - break; - - // US pages - case 'EXECUTIVE': // 7.25 in x 10.5 in - $sizes = [522.00, 756.00]; - break; - case 'FOLIO': // 8.5 in x 13 in - $sizes = [612.00, 936.00]; - break; - case 'FOOLSCAP': // 13.5 in x 17 in - $sizes = [972.00, 1224.00]; - break; - case 'LEDGER': // 11 in x 17 in - $sizes = [792.00, 1224.00]; - break; - case 'LEGAL': // 8.5 in x 14 in - $sizes = [612.00, 1008.00]; - break; - case 'LETTER': // 8.5 in x 11 in - $sizes = [612.00, 792.00]; - break; - case 'QUARTO': // 8.46 in x 10.8 in - $sizes = [609.12, 777.50]; - break; - case 'STATEMENT': // 5.5 in x 8.5 in - $sizes = [396.00, 612.00]; - break; - case 'USGOVT': // 8 in x 11 in - $sizes = [576.00, 792.00]; - break; - default: - $this->pageFormat = 'A4'; - $sizes = [595.28, 841.89]; - break; - } - $this->pagew = $sizes[0]; - $this->pageh = $sizes[1]; - } else { - if ($this->pagew < 10) { - throw new \DomainException('REPORT ERROR ReportBase::setup(): For custom size pages you must set "customwidth" larger then this in the XML file'); - } - if ($this->pageh < 10) { - throw new \DomainException('REPORT ERROR ReportBase::setup(): For custom size pages you must set "customheight" larger then this in the XML file'); - } - } - - return 0; - } - - /** - * Process the Header , Page header, Body or Footer - ReportBase - * - * @param string $p Header (H), Page header (PH), Body (B) or Footer (F) - * - * @return int - */ - public function setProcessing($p) { - $this->processing = $p; - - return 0; - } - - /** - * Add the Title when raw character data is used in Title - ReportBase - * - * @param string $data - * - * @return int - */ - public function addTitle($data) { - $this->title .= $data; - - return 0; - } - - /** - * Add the Description when raw character data is used in Description - ReportBase - * - * @param string $data - * - * @return int - */ - public function addDescription($data) { - $this->rsubject .= $data; - - return 0; - } - - /** - * Add Style to Styles array - ReportBase - * - * @param array $style - * - * @return int - */ - public function addStyle($style) { - $this->Styles[$style['name']] = $style; - - return 0; - } - - /** - * Get a style from the Styles array - ReportBase - * - * @param string $s Style name - * - * @return array - */ - public function getStyle($s) { - if (!isset($this->Styles[$s])) { - return current($this->Styles); - } - - return $this->Styles[$s]; - } +class ReportBase +{ + /** User measure unit. */ + const UNITS = 'pt'; + + /** webtrees URL */ + const WT_URL = WT_WEBTREES_URL; + + /** @var float Left Margin (expressed in points) Default: 17.99 mm, 0.7083 inch */ + public $leftmargin = 51.0; + + /** @var float Right Margin (expressed in points) Default: 9.87 mm, 0.389 inch */ + public $rightmargin = 28.0; + + /** @var float Top Margin (expressed in points) Default: 26.81 mm */ + public $topmargin = 76.0; + + /** @var float Bottom Margin (expressed in points) Default: 21.6 mm */ + public $bottommargin = 60.0; + + /** @var float Header Margin (expressed in points) Default: 4.93 mm */ + public $headermargin = 14.0; + + /** @var float Footer Margin (expressed in points) Default: 9.88 mm, 0.389 inch */ + public $footermargin = 28.0; + + /** @var string Page orientation (portrait, landscape) */ + public $orientation = 'portrait'; + + /** @var string Page format name */ + public $pageFormat = 'A4'; + + /** @var float Height of page format in points */ + public $pageh = 0.0; + + /** @var float Width of page format in points */ + public $pagew = 0.0; + + /** @var string[][] An array of the Styles elements found in the document */ + public $Styles = []; + + /** @var string The default Report font name */ + public $defaultFont = 'dejavusans'; + + /** @var int The default Report font size */ + public $defaultFontSize = 12; + + /** @var string Header (H), Page header (PH), Body (B) or Footer (F) */ + public $processing = 'H'; + + /** @var bool RTL Language (false=LTR, true=RTL) */ + public $rtl = false; + + /** @var bool Show the Generated by... (true=show the text) */ + public $showGenText = true; + + /** @var string Generated By... text */ + public $generatedby = ''; + + /** @var string The report title */ + public $title = ''; + + /** @var string Author of the report, the users full name */ + public $rauthor = WT_WEBTREES . ' ' . WT_VERSION; + + /** @var string Keywords */ + public $rkeywords = ''; + + /** @var string Report Description / Subject */ + public $rsubject = ''; + + /** + * Initial Setup - ReportBase + * + * Setting up document wide defaults that will be inherited of the report modules + * As DEFAULT A4 and Portrait will be used if not set + */ + public function setup() + { + // Set RTL direction + if (I18N::direction() === 'rtl') { + $this->rtl = true; + } + // Set the Keywords + $this->rkeywords = ''; + // Generated By...text + // I18N: This is a report footer. %s is the name of the application. + $this->generatedby = I18N::translate('Generated by %s', WT_WEBTREES . ' ' . WT_VERSION); + + // For known size pages + if ($this->pagew == 0 && $this->pageh == 0) { + /** + * The current ISO 216 standard was introduced in 1975 and is a direct follow up to the german DIN 476 standard from 1922. ISO 216 is also called EN 20216 in Europe. + * The ISO paper sizes are based on the metric system so everything else is aproxiamte + * + * The Series A is used for Standard Printing and Stationary. + * The Series B is used for Posters, Wall-Charts etc. + * The C series is used for folders, post cards and envelopes. C series envelope is suitable to insert A series sizes. + * ISO also define format series RA and SRA for untrimmed raw paper, where SRA stands for 'supplementary raw format A'. + * Japan has adopted the ISO series A sizes, but its series B sizes are slightly different. These sizes are sometimes called JIS B or JB sizes. + * sun was a unit of length used in Japan and is equal to about 3.03 cm or 1.193 inches + * The United States, Canada, and in part Mexico, are today the only industrialized nations in which the ISO standard paper sizes are not yet widely used. + * + * A0 & A1 Technical drawings, posters + * A1 & A2 Flip charts + * A2 & A3 Drawings, diagrams, large tables + * A4 Letters, magazines, forms, catalogs, laser printer and copying machine output + * A5 Note pads + * A6 Postcards + * B5, A5, B6 A6 Books + * C4, C5, C6 Envelopes for A4 letters: unfolded (C4), folded once (C5), folded twice (C6) + * B4 & A3 Newspapers, supported by most copying machines in addition to A4 + * B8 & A8 Playing cards + * + * 1 inch = 72 points + * 1 mm = 2.8346457 points + * 1 inch = 25.4 mm + * 1 point = 0,35278 mm + */ + switch ($this->pageFormat) { + // ISO A series + case '4A0': // ISO 216, 1682 mm x 2378 mm + $sizes = [ + 4767.86, + 6740.79, + ]; + break; + case '2A0': // ISO 216, 1189 mm x 1682 mm + $sizes = [ + 3370.39, + 4767.86, + ]; + break; + case 'A0': // ISO 216, 841 mm x 1189mm + $sizes = [ + 2383.94, + 3370.39, + ]; + break; + case 'A1': // ISO 216, 594 mm x 841 mm + $sizes = [ + 1683.78, + 2383.94, + ]; + break; + case 'A2': // ISO 216, 420 mm x 594 mm + $sizes = [ + 1190.55, + 1683.78, + ]; + break; + case 'A3': // ISO 216, 297 mm x 420 mm + $sizes = [ + 841.89, + 1190.55, + ]; + break; + case 'A4': // ISO 216, 210 mm 297 mm + $sizes = [ + 595.28, + 841.89, + ]; + break; + case 'A5': // ISO 216, 148 mm x 210 mm + $sizes = [ + 419.53, + 595.28, + ]; + break; + case 'A6': // ISO 216, 105 mm x 148 mm + $sizes = [ + 297.64, + 419.53, + ]; + break; + case 'A7': // ISO 216, 74 mm x 105 mm + $sizes = [ + 209.76, + 297.64, + ]; + break; + case 'A8': // ISO 216, 52 mm x 74 mm + $sizes = [ + 147.40, + 209.76, + ]; + break; + case 'A9': // ISO 216, 37 mm x 52 mm + $sizes = [ + 104.88, + 147.40, + ]; + break; + case 'A10': // ISO 216, 26 mm x 37 mm + $sizes = [ + 73.70, + 104.88, + ]; + break; + + // ISO B series + case 'B0': // ISO 216, 1000 mm x 1414 mm + $sizes = [ + 2834.65, + 4008.19, + ]; + break; + case 'B1': // ISO 216, 707 mm x 1000 mm + $sizes = [ + 2004.09, + 2834.65, + ]; + break; + case 'B2': // ISO 216, 500 mm x 707 mm + $sizes = [ + 1417.32, + 2004.09, + ]; + break; + case 'B3': // ISO 216, 353 mm x 500 mm + $sizes = [ + 1000.63, + 1417.32, + ]; + break; + case 'B4': // ISO 216, 250 mm x 353 mm + $sizes = [ + 708.66, + 1000.63, + ]; + break; + case 'B5': // ISO 216, 176 mm x 250 mm + $sizes = [ + 498.90, + 708.66, + ]; + break; + case 'B6': // ISO 216, 125 mm x 176 mm + $sizes = [ + 354.33, + 498.90, + ]; + break; + case 'B7': // ISO 216, 88 mm x 125 mm + $sizes = [ + 249.45, + 354.33, + ]; + break; + case 'B8': // ISO 216, 62 mm x 88 mm + $sizes = [ + 175.75, + 249.45, + ]; + break; + case 'B9': // ISO 216, 44 mm x 62 mm + $sizes = [ + 124.72, + 175.75, + ]; + break; + case 'B10': // ISO 216, 31 mm x 44 mm + $sizes = [ + 87.87, + 124.72, + ]; + break; + + // ISO C series, Envelope + case 'C0': // ISO 269, 917 mm x 1297 mm, For flat A0 sheet + $sizes = [ + 2599.37, + 3676.54, + ]; + break; + case 'C1': // ISO 269, 648 mm x 917 mm, For flat A1 sheet + $sizes = [ + 1836.85, + 2599.37, + ]; + break; + case 'C2': // ISO 269, 458 mm x 648 mm, For flat A2 sheet, A1 folded in half + $sizes = [ + 1298.27, + 1836.85, + ]; + break; + case 'C3': // ISO 269, 324 mm x 458 mm, For flat A3 sheet, A2 folded in half + $sizes = [ + 918.43, + 1298.27, + ]; + break; + case 'C4': // ISO 269, 229 mm x 324 mm, For flat A4 sheet, A3 folded in half + $sizes = [ + 649.13, + 918.43, + ]; + break; + case 'C5': // ISO 269, 162 mm x 229 mm, For flat A5 sheet, A4 folded in half + $sizes = [ + 459.21, + 649.13, + ]; + break; + case 'C6/5': // ISO 269, 114 mm x 229 mm. A5 folded twice = 1/3 A4. Alternative for the DL envelope + $sizes = [ + 323.15, + 649.13, + ]; + break; + case 'C6': // ISO 269, 114 mm x 162 mm, For A5 folded in half + $sizes = [ + 323.15, + 459.21, + ]; + break; + case 'C7/6': // ISO 269, 81 mm x 162 mm, For A5 sheet folded in thirds + $sizes = [ + 229.61, + 459.21, + ]; + break; + case 'C7': // ISO 269, 81 mm x 114 mm, For A5 folded in quarters + $sizes = [ + 229.61, + 323.15, + ]; + break; + case 'C8': // ISO 269, 57 mm x 81 mm + $sizes = [ + 161.57, + 229.61, + ]; + break; + case 'C9': // ISO 269, 40 mm x 57 mm + $sizes = [ + 113.39, + 161.57, + ]; + break; + case 'C10': // ISO 269, 28 mm x 40 mm + $sizes = [ + 79.37, + 113.39, + ]; + break; + case 'DL': // Original DIN 678 but ISO 269 now has this C6/5 , 110 mm x 220 mm, For A4 sheet folded in thirds, A5 in half + $sizes = [ + 311.81, + 623.62, + ]; + break; + + // Untrimmed stock sizes for the ISO-A Series - ISO primary range + case 'RA0': // ISO 478, 860 mm x 1220 mm + $sizes = [ + 2437.80, + 3458.27, + ]; + break; + case 'RA1': // ISO 478, 610 mm x 860 mm + $sizes = [ + 1729.13, + 2437.80, + ]; + break; + case 'RA2': // ISO 478, 430 mm x 610 mm + $sizes = [ + 1218.90, + 1729.13, + ]; + break; + case 'RA3': // ISO 478, 305 mm x 430 mm + $sizes = [ + 864.57, + 1218.90, + ]; + break; + case 'RA4': // ISO 478, 215 mm x 305 mm + $sizes = [ + 609.45, + 864.57, + ]; + break; + + // Untrimmed stock sizes for the ISO-A Series - ISO supplementary range + case 'SRA0': // ISO 593, 900 mm x 1280 mm + $sizes = [ + 2551.18, + 3628.35, + ]; + break; + case 'SRA1': // ISO 593, 640 mm x 900 mm + $sizes = [ + 1814.17, + 2551.18, + ]; + break; + case 'SRA2': // ISO 593, 450 mm x 640 mm + $sizes = [ + 1275.59, + 1814.17, + ]; + break; + case 'SRA3': // ISO 593, 320 mm x 450 mm + $sizes = [ + 907.09, + 1275.59, + ]; + break; + case 'SRA4': // ISO 593, 225 mm x 320 mm + $sizes = [ + 637.80, + 907.09, + ]; + break; + + // ISO size variations + case 'A2EXTRA': // ISO 216, 445 mm x 619 mm + $sizes = [ + 1261.42, + 1754.65, + ]; + break; + case 'A2SUPER': // ISO 216, 305 mm x 508 mm + $sizes = [ + 864.57, + 1440.00, + ]; + break; + case 'A3EXTRA': // ISO 216, 322 mm x 445 mm + $sizes = [ + 912.76, + 1261.42, + ]; + break; + case 'SUPERA3': // ISO 216, 305 mm x 487 mm + $sizes = [ + 864.57, + 1380.47, + ]; + break; + case 'A4EXTRA': // ISO 216, 235 mm x 322 mm + $sizes = [ + 666.14, + 912.76, + ]; + break; + case 'A4LONG': // ISO 216, 210 mm x 348 mm + $sizes = [ + 595.28, + 986.46, + ]; + break; + case 'A4SUPER': // ISO 216, 229 mm x 322 mm + $sizes = [ + 649.13, + 912.76, + ]; + break; + case 'SUPERA4': // ISO 216, 227 mm x 356 mm + $sizes = [ + 643.46, + 1009.13, + ]; + break; + case 'A5EXTRA': // ISO 216, 173 mm x 235 mm + $sizes = [ + 490.39, + 666.14, + ]; + break; + case 'SOB5EXTRA': // ISO 216, 202 mm x 276 mm + $sizes = [ + 572.60, + 782.36, + ]; + break; + + // Japanese version of the ISO 216 B series + case 'JB0': // JIS P 0138-61, 1030 mm x 1456 mm + $sizes = [ + 2919.69, + 4127.24, + ]; + break; + case 'JB1': // JIS P 0138-61, 728 mm x 1030 mm + $sizes = [ + 2063.62, + 2919.69, + ]; + break; + case 'JB2': // JIS P 0138-61, 515 mm x 728 mm + $sizes = [ + 1459.84, + 2063.62, + ]; + break; + case 'JB3': // JIS P 0138-61, 364 mm x 515 mm + $sizes = [ + 1031.81, + 1459.84, + ]; + break; + case 'JB4': // JIS P 0138-61, 257 mm x 364 mm + $sizes = [ + 728.50, + 1031.81, + ]; + break; + case 'JB5': // JIS P 0138-61, 182 mm x 257 mm + $sizes = [ + 515.91, + 728.50, + ]; + break; + case 'JB6': // JIS P 0138-61, 128 mm x 182 mm + $sizes = [ + 362.83, + 515.91, + ]; + break; + case 'JB7': // JIS P 0138-61, 91 mm x 128 mm + $sizes = [ + 257.95, + 362.83, + ]; + break; + case 'JB8': // JIS P 0138-61, 64 mm x 91 mm + $sizes = [ + 181.42, + 257.95, + ]; + break; + case 'JB9': // JIS P 0138-61, 45 mm x 64 mm + $sizes = [ + 127.56, + 181.42, + ]; + break; + case 'JB10': // JIS P 0138-61, 32 mm x 45 mm + $sizes = [ + 90.71, + 127.56, + ]; + break; + + // US pages + case 'EXECUTIVE': // 7.25 in x 10.5 in + $sizes = [ + 522.00, + 756.00, + ]; + break; + case 'FOLIO': // 8.5 in x 13 in + $sizes = [ + 612.00, + 936.00, + ]; + break; + case 'FOOLSCAP': // 13.5 in x 17 in + $sizes = [ + 972.00, + 1224.00, + ]; + break; + case 'LEDGER': // 11 in x 17 in + $sizes = [ + 792.00, + 1224.00, + ]; + break; + case 'LEGAL': // 8.5 in x 14 in + $sizes = [ + 612.00, + 1008.00, + ]; + break; + case 'LETTER': // 8.5 in x 11 in + $sizes = [ + 612.00, + 792.00, + ]; + break; + case 'QUARTO': // 8.46 in x 10.8 in + $sizes = [ + 609.12, + 777.50, + ]; + break; + case 'STATEMENT': // 5.5 in x 8.5 in + $sizes = [ + 396.00, + 612.00, + ]; + break; + case 'USGOVT': // 8 in x 11 in + $sizes = [ + 576.00, + 792.00, + ]; + break; + default: + $this->pageFormat = 'A4'; + $sizes = [ + 595.28, + 841.89, + ]; + break; + } + $this->pagew = $sizes[0]; + $this->pageh = $sizes[1]; + } else { + if ($this->pagew < 10) { + throw new \DomainException('REPORT ERROR ReportBase::setup(): For custom size pages you must set "customwidth" larger then this in the XML file'); + } + if ($this->pageh < 10) { + throw new \DomainException('REPORT ERROR ReportBase::setup(): For custom size pages you must set "customheight" larger then this in the XML file'); + } + } + + return 0; + } + + /** + * Process the Header , Page header, Body or Footer - ReportBase + * + * @param string $p Header (H), Page header (PH), Body (B) or Footer (F) + * + * @return int + */ + public function setProcessing($p) + { + $this->processing = $p; + + return 0; + } + + /** + * Add the Title when raw character data is used in Title - ReportBase + * + * @param string $data + * + * @return int + */ + public function addTitle($data) + { + $this->title .= $data; + + return 0; + } + + /** + * Add the Description when raw character data is used in Description - ReportBase + * + * @param string $data + * + * @return int + */ + public function addDescription($data) + { + $this->rsubject .= $data; + + return 0; + } + + /** + * Add Style to Styles array - ReportBase + * + * @param array $style + * + * @return int + */ + public function addStyle($style) + { + $this->Styles[$style['name']] = $style; + + return 0; + } + + /** + * Get a style from the Styles array - ReportBase + * + * @param string $s Style name + * + * @return array + */ + public function getStyle($s) + { + if (!isset($this->Styles[$s])) { + return current($this->Styles); + } + + return $this->Styles[$s]; + } } diff --git a/app/Report/ReportBaseCell.php b/app/Report/ReportBaseCell.php index 88a7d817cb..631478fcbd 100644 --- a/app/Report/ReportBaseCell.php +++ b/app/Report/ReportBaseCell.php @@ -18,172 +18,177 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportBaseCell */ -class ReportBaseCell extends ReportBaseElement { - /** - * Allows to center or align the text. Possible values are: - * - * @var string - */ - public $align = ''; - /** - * Whether or not a border should be printed around this box. 0 = no border, 1 = border. Default is 0. - * Or a string containing some or all of the following characters (in any order): - * - * @var mixed - */ - public $border; - /** - * Border color in HTML code - * - * @var string - */ - public $bocolor; - /** - * The HTML color code to fill the background of this cell. - * - * @var string - */ - public $bgcolor; - /** - * Indicates if the cell background must be painted (1) or transparent (0). Default value: 1. - * If no background color is set then it will not be painted - * - * @var int - */ - public $fill; - /** - * Cell height DEFAULT 0 (expressed in points) - * The starting height of this cell. If the text wraps the height will automatically be adjusted. - * - * @var int - */ - public $height; - /** - * Left position in user units (X-position). Default is the current position - * - * @var mixed - */ - public $left; - /** - * Indicates where the current position should go after the call. Possible values are: - * - * @var int - */ - public $newline; - /** - * The name of the Style that should be used to render the text. - * - * @var string - */ - public $styleName; - /** - * Stretch carachter mode: - * - * @var int - */ - public $stretch; - /** - * Text color in HTML code - * - * @var string - */ - public $tcolor; - /** - * Top position in user units (Y-position). Default is the current position - * - * @var mixed - */ - public $top; - /** - * URL address - * - * @var string - */ - public $url; - /** - * Cell width DEFAULT 0 (expressed in points) - * Setting the width to 0 will make it the width from the current location to the right margin. - * - * @var int - */ - public $width; +class ReportBaseCell extends ReportBaseElement +{ + /** + * Allows to center or align the text. Possible values are: + * + * @var string + */ + public $align = ''; + /** + * Whether or not a border should be printed around this box. 0 = no border, 1 = border. Default is 0. + * Or a string containing some or all of the following characters (in any order): + * + * @var mixed + */ + public $border; + /** + * Border color in HTML code + * + * @var string + */ + public $bocolor; + /** + * The HTML color code to fill the background of this cell. + * + * @var string + */ + public $bgcolor; + /** + * Indicates if the cell background must be painted (1) or transparent (0). Default value: 1. + * If no background color is set then it will not be painted + * + * @var int + */ + public $fill; + /** + * Cell height DEFAULT 0 (expressed in points) + * The starting height of this cell. If the text wraps the height will automatically be adjusted. + * + * @var int + */ + public $height; + /** + * Left position in user units (X-position). Default is the current position + * + * @var mixed + */ + public $left; + /** + * Indicates where the current position should go after the call. Possible values are: + * + * @var int + */ + public $newline; + /** + * The name of the Style that should be used to render the text. + * + * @var string + */ + public $styleName; + /** + * Stretch carachter mode: + * + * @var int + */ + public $stretch; + /** + * Text color in HTML code + * + * @var string + */ + public $tcolor; + /** + * Top position in user units (Y-position). Default is the current position + * + * @var mixed + */ + public $top; + /** + * URL address + * + * @var string + */ + public $url; + /** + * Cell width DEFAULT 0 (expressed in points) + * Setting the width to 0 will make it the width from the current location to the right margin. + * + * @var int + */ + public $width; - /** @var int Unknown */ - public $reseth; + /** @var int Unknown */ + public $reseth; - /** - * CELL - Element - * - * @param int $width cell width (expressed in points) - * @param int $height cell height (expressed in points) - * @param mixed $border Border style - * @param string $align Text alignement - * @param string $bgcolor Background color code - * @param string $style The name of the text style - * @param int $ln Indicates where the current position should go after the call - * @param mixed $top Y-position - * @param mixed $left X-position - * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. - * @param int $stretch Stretch carachter mode - * @param string $bocolor Border color - * @param string $tcolor Text color - * @param $reseth - */ - public function __construct( - $width, $height, $border, $align, $bgcolor, $style, $ln, $top, $left, $fill, $stretch, $bocolor, $tcolor, $reseth - ) { - $this->align = $align; - $this->border = $border; - $this->bgcolor = $bgcolor; - $this->bocolor = $bocolor; - $this->fill = $fill; - $this->height = $height; - $this->left = $left; - $this->newline = $ln; - $this->styleName = $style; - $this->text = ''; - $this->tcolor = $tcolor; - $this->top = $top; - $this->url = ''; - $this->stretch = $stretch; - $this->width = $width; - $this->reseth = $reseth; + /** + * CELL - Element + * + * @param int $width cell width (expressed in points) + * @param int $height cell height (expressed in points) + * @param mixed $border Border style + * @param string $align Text alignement + * @param string $bgcolor Background color code + * @param string $style The name of the text style + * @param int $ln Indicates where the current position should go after the call + * @param mixed $top Y-position + * @param mixed $left X-position + * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. + * @param int $stretch Stretch carachter mode + * @param string $bocolor Border color + * @param string $tcolor Text color + * @param $reseth + */ + public function __construct( + $width, $height, $border, $align, $bgcolor, $style, $ln, $top, $left, $fill, $stretch, $bocolor, $tcolor, $reseth + ) + { + $this->align = $align; + $this->border = $border; + $this->bgcolor = $bgcolor; + $this->bocolor = $bocolor; + $this->fill = $fill; + $this->height = $height; + $this->left = $left; + $this->newline = $ln; + $this->styleName = $style; + $this->text = ''; + $this->tcolor = $tcolor; + $this->top = $top; + $this->url = ''; + $this->stretch = $stretch; + $this->width = $width; + $this->reseth = $reseth; - return 0; - } + return 0; + } - /** - * Get the cell height - * - * @param $renderer - * - * @return float - */ - public function getHeight($renderer) { - return $this->height; - } + /** + * Get the cell height + * + * @param $renderer + * + * @return float + */ + public function getHeight($renderer) + { + return $this->height; + } - /** - * Sets the current cells URL - * - * @param string $url The URL address to save - * - * @return int - */ - public function setUrl($url) { - $this->url = $url; + /** + * Sets the current cells URL + * + * @param string $url The URL address to save + * + * @return int + */ + public function setUrl($url) + { + $this->url = $url; - return 0; - } + return 0; + } - /** - * Get the cell width - * - * @param $renderer - * - * @return float - */ - public function getWidth($renderer) { - return $this->width; - } + /** + * Get the cell width + * + * @param $renderer + * + * @return float + */ + public function getWidth($renderer) + { + return $this->width; + } } diff --git a/app/Report/ReportBaseElement.php b/app/Report/ReportBaseElement.php index ffede002a3..cb5e5f2f07 100644 --- a/app/Report/ReportBaseElement.php +++ b/app/Report/ReportBaseElement.php @@ -18,104 +18,120 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportBaseElement */ -class ReportBaseElement { - /** @var string Text*/ - public $text = ''; +class ReportBaseElement +{ + /** @var string Text */ + public $text = ''; - /** - * Element renderer - * - * @param ReportHtml|ReportTcpdf $renderer - */ - public function render($renderer) { - //-- to be implemented in inherited classes - } + /** + * Element renderer + * + * @param ReportHtml|ReportTcpdf $renderer + */ + public function render($renderer) + { + //-- to be implemented in inherited classes + } - /** - * Get the height. - * - * @param ReportHtml|ReportTcpdf $renderer - * - * @return float - */ - public function getHeight($renderer) { - return 0.0; - } + /** + * Get the height. + * + * @param ReportHtml|ReportTcpdf $renderer + * + * @return float + */ + public function getHeight($renderer) + { + return 0.0; + } - /** - * Get the width. - * - * @param ReportHtml|ReportTcpdf $renderer - * - * @return float - */ - public function getWidth($renderer) { - return 0.0; - } + /** + * Get the width. + * + * @param ReportHtml|ReportTcpdf $renderer + * + * @return float + */ + public function getWidth($renderer) + { + return 0.0; + } - /** - * Add text. - * - * @param string $t - * - * @return int - */ - public function addText($t) { - $t = trim($t, "\r\n\t"); - $t = str_replace(['
', ' '], ["\n", ' '], $t); - $t = strip_tags($t); - $t = htmlspecialchars_decode($t); - $this->text .= $t; + /** + * Add text. + * + * @param string $t + * + * @return int + */ + public function addText($t) + { + $t = trim($t, "\r\n\t"); + $t = str_replace([ + '
', + ' ', + ], [ + "\n", + ' ', + ], $t); + $t = strip_tags($t); + $t = htmlspecialchars_decode($t); + $this->text .= $t; - return 0; - } + return 0; + } - /** - * Add an end-of-line. - * - * @return int - */ - public function addNewline() { - $this->text .= "\n"; + /** + * Add an end-of-line. + * + * @return int + */ + public function addNewline() + { + $this->text .= "\n"; - return 0; - } + return 0; + } - /** - * Get the current text. - * - * @return string - */ - public function getValue() { - return $this->text; - } + /** + * Get the current text. + * + * @return string + */ + public function getValue() + { + return $this->text; + } - /** - * Set the width to wrap text. - * - * @param $wrapwidth - * @param $cellwidth - * - * @return int - */ - public function setWrapWidth($wrapwidth, $cellwidth) { - return 0; - } + /** + * Set the width to wrap text. + * + * @param $wrapwidth + * @param $cellwidth + * + * @return int + */ + public function setWrapWidth($wrapwidth, $cellwidth) + { + return 0; + } - /** - * Render the footnotes. - * - * @param $renderer - */ - public function renderFootnote($renderer) { - } + /** + * Render the footnotes. + * + * @param $renderer + */ + public function renderFootnote($renderer) + { + } - /** - * Set the text. - * - * @param $text - */ - public function setText($text) { - $this->text = $text; - } + /** + * Set the text. + * + * @param $text + */ + public function setText($text) + { + $this->text = $text; + } } diff --git a/app/Report/ReportBaseFootnote.php b/app/Report/ReportBaseFootnote.php index ae38626358..50989aec93 100644 --- a/app/Report/ReportBaseFootnote.php +++ b/app/Report/ReportBaseFootnote.php @@ -18,119 +18,131 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportBaseFootnote */ -class ReportBaseFootnote extends ReportBaseElement { - /** - * The name of the style for this element - * - * @var string - */ - public $styleName = ''; +class ReportBaseFootnote extends ReportBaseElement +{ + /** + * The name of the style for this element + * + * @var string + */ + public $styleName = ''; - /** - * Numbers for the links - * - * @var int - */ - public $num; + /** + * Numbers for the links + * + * @var int + */ + public $num; - /** - * The text that will be printed with the number - * - * @var string - */ - public $numText = ''; + /** + * The text that will be printed with the number + * + * @var string + */ + public $numText = ''; - /** - * Remaining width of a cell - * - * @var float User unit (points) - */ - public $wrapWidthRemaining; + /** + * Remaining width of a cell + * + * @var float User unit (points) + */ + public $wrapWidthRemaining; - /** - * Original width of a cell - * - * @var float User unit (points) - */ - public $wrapWidthCell; + /** + * Original width of a cell + * + * @var float User unit (points) + */ + public $wrapWidthCell; - /** @var string A link */ - public $addlink; + /** @var string A link */ + public $addlink; - /** - * Createa an element. - * - * @param string $style - */ - public function __construct($style = '') { - $this->text = ''; - if (!empty($style)) { - $this->styleName = $style; - } else { - $this->styleName = 'footnote'; - } - } + /** + * Createa an element. + * + * @param string $style + */ + public function __construct($style = '') + { + $this->text = ''; + if (!empty($style)) { + $this->styleName = $style; + } else { + $this->styleName = 'footnote'; + } + } - /** - * Add text. - * - * @param $t - * - * @return int - */ - public function addText($t) { - $t = trim($t, "\r\n\t"); - $t = str_replace(['
', ' '], ["\n", ' '], $t); - $t = strip_tags($t); - $t = htmlspecialchars_decode($t); - $this->text .= $t; + /** + * Add text. + * + * @param $t + * + * @return int + */ + public function addText($t) + { + $t = trim($t, "\r\n\t"); + $t = str_replace([ + '
', + ' ', + ], [ + "\n", + ' ', + ], $t); + $t = strip_tags($t); + $t = htmlspecialchars_decode($t); + $this->text .= $t; - return 0; - } + return 0; + } - /** - * Set the width to wrap text. - * - * @param $wrapwidth - * @param $cellwidth - * - * @return mixed - */ - public function setWrapWidth($wrapwidth, $cellwidth) { - $this->wrapWidthCell = $cellwidth; - if (strpos($this->numText, "\n") !== false) { - $this->wrapWidthRemaining = $cellwidth; - } else { - $this->wrapWidthRemaining = $wrapwidth; - } + /** + * Set the width to wrap text. + * + * @param $wrapwidth + * @param $cellwidth + * + * @return mixed + */ + public function setWrapWidth($wrapwidth, $cellwidth) + { + $this->wrapWidthCell = $cellwidth; + if (strpos($this->numText, "\n") !== false) { + $this->wrapWidthRemaining = $cellwidth; + } else { + $this->wrapWidthRemaining = $wrapwidth; + } - return $this->wrapWidthRemaining; - } + return $this->wrapWidthRemaining; + } - /** - * Set the number. - * - * @param $n - * - * @return int - */ - public function setNum($n) { - $this->num = $n; - $this->numText = "$n "; + /** + * Set the number. + * + * @param $n + * + * @return int + */ + public function setNum($n) + { + $this->num = $n; + $this->numText = "$n "; - return 0; - } + return 0; + } - /** - * Add a link. - * - * @param $a - * - * @return int - */ - public function setAddlink($a) { - $this->addlink = $a; + /** + * Add a link. + * + * @param $a + * + * @return int + */ + public function setAddlink($a) + { + $this->addlink = $a; - return 0; - } + return 0; + } } diff --git a/app/Report/ReportBaseHtml.php b/app/Report/ReportBaseHtml.php index a5252e4d95..8011baa327 100644 --- a/app/Report/ReportBaseHtml.php +++ b/app/Report/ReportBaseHtml.php @@ -18,59 +18,64 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportBaseHtml */ -class ReportBaseHtml extends ReportBaseElement { - /** @var string The XML tag. */ - public $tag; +class ReportBaseHtml extends ReportBaseElement +{ + /** @var string The XML tag. */ + public $tag; - /** @var string[] Attributes of the XML tag. */ - public $attrs; + /** @var string[] Attributes of the XML tag. */ + public $attrs; - /** @var ReportBaseElement[] A list of elements. */ - public $elements = []; + /** @var ReportBaseElement[] A list of elements. */ + public $elements = []; - /** - * Create an element. - * - * @param $tag - * @param $attrs - */ - public function __construct($tag, $attrs) { - $this->tag = $tag; - $this->attrs = $attrs; + /** + * Create an element. + * + * @param $tag + * @param $attrs + */ + public function __construct($tag, $attrs) + { + $this->tag = $tag; + $this->attrs = $attrs; - return 0; - } + return 0; + } - /** - * Get the start tag. - * - * @return string - */ - public function getStart() { - $str = '<' . $this->tag . ' '; - foreach ($this->attrs as $key => $value) { - $str .= $key . '="' . $value . '" '; - } - $str .= '>'; + /** + * Get the start tag. + * + * @return string + */ + public function getStart() + { + $str = '<' . $this->tag . ' '; + foreach ($this->attrs as $key => $value) { + $str .= $key . '="' . $value . '" '; + } + $str .= '>'; - return $str; - } + return $str; + } - /** - * Get the end tag. - * - * @return string - */ - public function getEnd() { - return 'tag . '>'; - } + /** + * Get the end tag. + * + * @return string + */ + public function getEnd() + { + return 'tag . '>'; + } - /** - * Add an element. - * - * @param ReportBaseElement $element - */ - public function addElement($element) { - $this->elements[] = $element; - } + /** + * Add an element. + * + * @param ReportBaseElement $element + */ + public function addElement($element) + { + $this->elements[] = $element; + } } diff --git a/app/Report/ReportBaseImage.php b/app/Report/ReportBaseImage.php index df28c9afb6..82e28c8a4c 100644 --- a/app/Report/ReportBaseImage.php +++ b/app/Report/ReportBaseImage.php @@ -18,92 +18,96 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportBaseImage */ -class ReportBaseImage extends ReportBaseElement { - /** - * Filename of the image - * - * @var string - */ - public $file; - /** - * Height of the image - * - * @var float - */ - public $height; - /** - * Width of the image - * - * @var float - */ - public $width; - /** - * X-position (left) of the image - * - * @var float - */ - public $x; - /** - * Y-position (top) of the image - * - * @var float - */ - public $y; - /** - * Placement fo the image. L: left, C:center, R:right - * - * @var string - */ - public $align = ''; - /** - * T:same line, N:next line - * - * @var string - */ - public $line = ''; +class ReportBaseImage extends ReportBaseElement +{ + /** + * Filename of the image + * + * @var string + */ + public $file; + /** + * Height of the image + * + * @var float + */ + public $height; + /** + * Width of the image + * + * @var float + */ + public $width; + /** + * X-position (left) of the image + * + * @var float + */ + public $x; + /** + * Y-position (top) of the image + * + * @var float + */ + public $y; + /** + * Placement fo the image. L: left, C:center, R:right + * + * @var string + */ + public $align = ''; + /** + * T:same line, N:next line + * + * @var string + */ + public $line = ''; - /** - * Image class function - Base - * - * @param string $file Filename of the image - * @param float $x X-position (left) of the image - * @param float $y Y-position (top) of the image - * @param float $w Width of the image - * @param float $h Height of the image - * @param string $align Placement of the image. L: left, C:center, R:right - * @param string $ln T:same line, N:next line - */ - public function __construct($file, $x, $y, $w, $h, $align, $ln) { - $this->file = $file; - $this->width = $w; - $this->height = $h; - $this->x = $x; - $this->y = $y; - $this->align = $align; - $this->line = $ln; + /** + * Image class function - Base + * + * @param string $file Filename of the image + * @param float $x X-position (left) of the image + * @param float $y Y-position (top) of the image + * @param float $w Width of the image + * @param float $h Height of the image + * @param string $align Placement of the image. L: left, C:center, R:right + * @param string $ln T:same line, N:next line + */ + public function __construct($file, $x, $y, $w, $h, $align, $ln) + { + $this->file = $file; + $this->width = $w; + $this->height = $h; + $this->x = $x; + $this->y = $y; + $this->align = $align; + $this->line = $ln; - return 0; - } + return 0; + } - /** - * Get the height. - * - * @param $renderer - * - * @return float - */ - public function getHeight($renderer) { - return $this->height; - } + /** + * Get the height. + * + * @param $renderer + * + * @return float + */ + public function getHeight($renderer) + { + return $this->height; + } - /** - * Get the width. - * - * @param $renderer - * - * @return float - */ - public function getWidth($renderer) { - return $this->width; - } + /** + * Get the width. + * + * @param $renderer + * + * @return float + */ + public function getWidth($renderer) + { + return $this->width; + } } diff --git a/app/Report/ReportBaseLine.php b/app/Report/ReportBaseLine.php index d785c437df..d1611f2b72 100644 --- a/app/Report/ReportBaseLine.php +++ b/app/Report/ReportBaseLine.php @@ -18,68 +18,72 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportBaseLine */ -class ReportBaseLine extends ReportBaseElement { - /** - * Start horizontal position, current position (default) - * - * @var mixed - */ - public $x1 = '.'; - /** - * Start vertical position, current position (default) - * - * @var mixed - */ - public $y1 = '.'; - /** - * End horizontal position, maximum width (default) - * - * @var mixed - */ - public $x2 = '.'; - /** - * End vertical position - * - * @var mixed - */ - public $y2 = '.'; +class ReportBaseLine extends ReportBaseElement +{ + /** + * Start horizontal position, current position (default) + * + * @var mixed + */ + public $x1 = '.'; + /** + * Start vertical position, current position (default) + * + * @var mixed + */ + public $y1 = '.'; + /** + * End horizontal position, maximum width (default) + * + * @var mixed + */ + public $x2 = '.'; + /** + * End vertical position + * + * @var mixed + */ + public $y2 = '.'; - /** - * Create a line class - Base - * - * @param mixed $x1 - * @param mixed $y1 - * @param mixed $x2 - * @param mixed $y2 - */ - public function __construct($x1, $y1, $x2, $y2) { - $this->x1 = $x1; - $this->y1 = $y1; - $this->x2 = $x2; - $this->y2 = $y2; + /** + * Create a line class - Base + * + * @param mixed $x1 + * @param mixed $y1 + * @param mixed $x2 + * @param mixed $y2 + */ + public function __construct($x1, $y1, $x2, $y2) + { + $this->x1 = $x1; + $this->y1 = $y1; + $this->x2 = $x2; + $this->y2 = $y2; - return 0; - } + return 0; + } - /** - * Get the height of the line. - * - * @param $renderer - * - * @return number - */ - public function getHeight($renderer) { - return abs($this->y2 - $this->y1); - } + /** + * Get the height of the line. + * + * @param $renderer + * + * @return number + */ + public function getHeight($renderer) + { + return abs($this->y2 - $this->y1); + } - /** - * Get the width of the line. - * - * @param $renderer - * - * @return number - */ - public function getWidth($renderer) { - return abs($this->x2 - $this->x1); - } + /** + * Get the width of the line. + * + * @param $renderer + * + * @return number + */ + public function getWidth($renderer) + { + return abs($this->x2 - $this->x1); + } } diff --git a/app/Report/ReportBasePageheader.php b/app/Report/ReportBasePageheader.php index e01968b097..9d3b3f0d0f 100644 --- a/app/Report/ReportBasePageheader.php +++ b/app/Report/ReportBasePageheader.php @@ -18,36 +18,40 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportBasePageheader */ -class ReportBasePageheader extends ReportBaseElement { - /** @var ReportBaseElement[] Elements */ - public $elements = []; +class ReportBasePageheader extends ReportBaseElement +{ + /** @var ReportBaseElement[] Elements */ + public $elements = []; - /** - * Create a page header - */ - public function __construct() { - $this->elements = []; + /** + * Create a page header + */ + public function __construct() + { + $this->elements = []; - return 0; - } + return 0; + } - /** - * Unknown? - * - * @return int - */ - public function textBox() { - $this->elements = []; + /** + * Unknown? + * + * @return int + */ + public function textBox() + { + $this->elements = []; - return 0; - } + return 0; + } - /** - * Add element - PageHeader - * - * @param ReportBaseElement $element - */ - public function addElement($element) { - $this->elements[] = $element; - } + /** + * Add element - PageHeader + * + * @param ReportBaseElement $element + */ + public function addElement($element) + { + $this->elements[] = $element; + } } diff --git a/app/Report/ReportBaseText.php b/app/Report/ReportBaseText.php index a9f268fc70..3254440879 100644 --- a/app/Report/ReportBaseText.php +++ b/app/Report/ReportBaseText.php @@ -18,72 +18,76 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportBaseText */ -class ReportBaseText extends ReportBaseElement { - /** - * Text color in HTML code - * - * @var string - */ - public $color; - /** - * Style name - * - * @var string - */ - public $styleName; - /** - * Remaining width of a cel - * - * @var int User unit (points) - */ - public $wrapWidthRemaining; - /** - * Original width of a cell - * - * @var int User unit (points) - */ - public $wrapWidthCell; +class ReportBaseText extends ReportBaseElement +{ + /** + * Text color in HTML code + * + * @var string + */ + public $color; + /** + * Style name + * + * @var string + */ + public $styleName; + /** + * Remaining width of a cel + * + * @var int User unit (points) + */ + public $wrapWidthRemaining; + /** + * Original width of a cell + * + * @var int User unit (points) + */ + public $wrapWidthCell; - /** - * Create a Text class - Base - * - * @param string $style The name of the text style - * @param string $color HTML color code - */ - public function __construct($style, $color) { - $this->text = ''; - $this->color = $color; - $this->wrapWidthRemaining = 0; - $this->styleName = $style; + /** + * Create a Text class - Base + * + * @param string $style The name of the text style + * @param string $color HTML color code + */ + public function __construct($style, $color) + { + $this->text = ''; + $this->color = $color; + $this->wrapWidthRemaining = 0; + $this->styleName = $style; - return 0; - } + return 0; + } - /** - * Set the width for word-wrapping. - * - * @param $wrapwidth - * @param $cellwidth - * - * @return mixed - */ - public function setWrapWidth($wrapwidth, $cellwidth) { - $this->wrapWidthCell = $cellwidth; - if (strpos($this->text, "\n") !== false) { - $this->wrapWidthRemaining = $cellwidth; - } else { - $this->wrapWidthRemaining = $wrapwidth; - } + /** + * Set the width for word-wrapping. + * + * @param $wrapwidth + * @param $cellwidth + * + * @return mixed + */ + public function setWrapWidth($wrapwidth, $cellwidth) + { + $this->wrapWidthCell = $cellwidth; + if (strpos($this->text, "\n") !== false) { + $this->wrapWidthRemaining = $cellwidth; + } else { + $this->wrapWidthRemaining = $wrapwidth; + } - return $this->wrapWidthRemaining; - } + return $this->wrapWidthRemaining; + } - /** - * Get the style name. - * - * @return string - */ - public function getStyleName() { - return $this->styleName; - } + /** + * Get the style name. + * + * @return string + */ + public function getStyleName() + { + return $this->styleName; + } } diff --git a/app/Report/ReportBaseTextbox.php b/app/Report/ReportBaseTextbox.php index fb116113ec..a6b8de0adc 100644 --- a/app/Report/ReportBaseTextbox.php +++ b/app/Report/ReportBaseTextbox.php @@ -18,141 +18,144 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportBaseTextbox */ -class ReportBaseTextbox extends ReportBaseElement { - /** - * Array of elements in the TextBox - * - * @var array - */ - public $elements = []; +class ReportBaseTextbox extends ReportBaseElement +{ + /** + * Array of elements in the TextBox + * + * @var array + */ + public $elements = []; - /** - * Background color in HTML code - * - * @var string - */ - public $bgcolor; - /** - * Whether or not paint the background - * - * @var bool - */ - public $fill; + /** + * Background color in HTML code + * + * @var string + */ + public $bgcolor; + /** + * Whether or not paint the background + * + * @var bool + */ + public $fill; - /** - * Position the left corner of this box on the page(expressed in points). The default is the current position. - * - * @var mixed - */ - public $left; - /** - * Position the top corner of this box on the page(expressed in points). the default is the current position - * - * @var mixed - */ - public $top; - /** - * After this box is finished rendering, should the next section of text start immediately after the this box or should it start on a new line under this box. 0 = no new line, 1 = force new line. Default is 0 - * - * @var bool - */ - public $newline; + /** + * Position the left corner of this box on the page(expressed in points). The default is the current position. + * + * @var mixed + */ + public $left; + /** + * Position the top corner of this box on the page(expressed in points). the default is the current position + * + * @var mixed + */ + public $top; + /** + * After this box is finished rendering, should the next section of text start immediately after the this box or should it start on a new line under this box. 0 = no new line, 1 = force new line. Default is 0 + * + * @var bool + */ + public $newline; - /** @var bool Unused? */ - public $pagecheck; + /** @var bool Unused? */ + public $pagecheck; - /** @var bool Whether to print a border */ - public $border; + /** @var bool Whether to print a border */ + public $border; - /** - * Style of rendering - * - * - * - * @var string - */ - public $style; + /** + * Style of rendering + * + * + * + * @var string + */ + public $style; - /** - * @var array Border style of rectangle. Array with keys among the following: - * - * Not yet in use - * var $borderstyle; - */ + /** + * @var array Border style of rectangle. Array with keys among the following: + * + * Not yet in use + * var $borderstyle; + */ - /** - * The starting height of this cell. If the text wraps the height will automatically be adjusted - * - * @var float - */ - public $height; - /** - * Setting the width to 0 will make it the width from the current location to the right margin - * - * @var float - */ - public $width; - /** - * Use cell padding or not - * - * @var bool - */ - public $padding; - /** - * Resets this box last height after it’s done - */ - public $reseth; + /** + * The starting height of this cell. If the text wraps the height will automatically be adjusted + * + * @var float + */ + public $height; + /** + * Setting the width to 0 will make it the width from the current location to the right margin + * + * @var float + */ + public $width; + /** + * Use cell padding or not + * + * @var bool + */ + public $padding; + /** + * Resets this box last height after it’s done + */ + public $reseth; - /** - * TextBox - Element - Base - * - * @param float $width Text box width - * @param float $height Text box height - * @param bool $border - * @param string $bgcolor Background color code in HTML - * @param bool $newline - * @param mixed $left - * @param mixed $top - * @param bool $pagecheck - * @param string $style - * @param bool $fill - * @param bool $padding - * @param bool $reseth - */ - public function __construct( - $width, $height, $border, $bgcolor, $newline, $left, $top, $pagecheck, $style, $fill, $padding, $reseth - ) { - $this->border = $border; - $this->bgcolor = $bgcolor; - $this->fill = $fill; - $this->height = $height; - $this->left = $left; - $this->newline = $newline; - $this->pagecheck = $pagecheck; - $this->style = $style; - $this->top = $top; - $this->width = $width; - $this->padding = $padding; - $this->reseth = $reseth; + /** + * TextBox - Element - Base + * + * @param float $width Text box width + * @param float $height Text box height + * @param bool $border + * @param string $bgcolor Background color code in HTML + * @param bool $newline + * @param mixed $left + * @param mixed $top + * @param bool $pagecheck + * @param string $style + * @param bool $fill + * @param bool $padding + * @param bool $reseth + */ + public function __construct( + $width, $height, $border, $bgcolor, $newline, $left, $top, $pagecheck, $style, $fill, $padding, $reseth + ) + { + $this->border = $border; + $this->bgcolor = $bgcolor; + $this->fill = $fill; + $this->height = $height; + $this->left = $left; + $this->newline = $newline; + $this->pagecheck = $pagecheck; + $this->style = $style; + $this->top = $top; + $this->width = $width; + $this->padding = $padding; + $this->reseth = $reseth; - return 0; - } + return 0; + } - /** - * Add an element to the TextBox - * - * @param object|string $element - */ - public function addElement($element) { - $this->elements[] = $element; - } + /** + * Add an element to the TextBox + * + * @param object|string $element + */ + public function addElement($element) + { + $this->elements[] = $element; + } } diff --git a/app/Report/ReportHtml.php b/app/Report/ReportHtml.php index 06aa160e5a..bdf31f9606 100644 --- a/app/Report/ReportHtml.php +++ b/app/Report/ReportHtml.php @@ -22,712 +22,759 @@ use Fisharebest\Webtrees\MediaFile; /** * Class ReportHtml */ -class ReportHtml extends ReportBase { - /** - * Cell padding - * - * @var int - */ - public $cPadding = 2; - - /** - * Cell height ratio - * - * @var float - */ - public $cellHeightRatio = 1.8; - - /** - * Current horizontal position - * - * @var float - */ - public $X = 0.0; - - /** - * Current vertical position - * - * @var float - */ - public $Y = 0.0; - - /** - * Currently used style name - * - * @var string - */ - public $currentStyle = ''; - - /** - * Page number counter - * - * @var int - */ - public $pageN = 1; - - /** - * Store the page width without left and right margins - * - * In HTML, we don't need this - * - * @var float - */ - public $noMarginWidth = 0.0; - - /** - * Last cell height - * - * @var float - */ - public $lastCellHeight = 0.0; - - /** - * LTR or RTL alignement; "left" on LTR, "right" on RTL - * Used in
- * - * @var string - */ - public $alignRTL = 'left'; - - /** - * LTR or RTL entity - * - * @var string - */ - public $entityRTL = '‎'; - - /** - * Largest Font Height is used by TextBox etc. - * - * Use this to calculate a the text height. - * This makes sure that the text fits into the cell/box when different font sizes are used - * - * @var int - */ - public $largestFontHeight = 0; - - /** - * Keep track of the highest Y position - * - * Used with Header div / Body div / Footer div / "addpage" / The bottom of the last image etc. - * - * @var float - */ - public $maxY = 0; - - /** @var ReportBaseElement[] Array of elements in the header */ - public $headerElements = []; - - /** @var ReportBaseElement[] Array of elements in the page header */ - public $pageHeaderElements = []; - - /** @var ReportBaseElement[] Array of elements in the footer */ - public $footerElements = []; - - /** @var ReportBaseElement[] Array of elements in the body */ - public $bodyElements = []; - - /** @var ReportBaseFootnote[] Array of elements in the footer notes */ - public $printedfootnotes = []; - - /** - * HTML Setup - ReportHtml - */ - public function setup() { - parent::setup(); - - // Setting up the correct dimensions if Portrait (default) or Landscape - if ($this->orientation == 'landscape') { - $tmpw = $this->pagew; - $this->pagew = $this->pageh; - $this->pageh = $tmpw; - } - // Store the pagewidth without margins - $this->noMarginWidth = (int) ($this->pagew - $this->leftmargin - $this->rightmargin); - // If RTL - if ($this->rtl) { - $this->alignRTL = 'right'; - $this->entityRTL = '‏'; - } - // Change the default HTML font name - $this->defaultFont = 'Arial'; - - if ($this->showGenText) { - // The default style name for Generated by.... is 'genby' - $element = new ReportHtmlCell(0, 10, 0, 'C', '', 'genby', 1, '.', '.', 0, 0, '', '', true); - $element->addText($this->generatedby); - $element->setUrl(parent::WT_URL); - $this->footerElements[] = $element; - } - } - - /** - * Add an element. - * - * @param $element - */ - public function addElement($element) { - if ($this->processing == 'B') { - $this->bodyElements[] = $element; - } elseif ($this->processing == 'H') { - $this->headerElements[] = $element; - } elseif ($this->processing == 'F') { - $this->footerElements[] = $element; - } - } - - /** - * Generate the page header - */ - public function runPageHeader() { - foreach ($this->pageHeaderElements as $element) { - if (is_object($element)) { - $element->render($this); - } elseif (is_string($element) && $element == 'footnotetexts') { - $this->footnotes(); - } elseif (is_string($element) && $element == 'addpage') { - $this->addPage(); - } - } - } - - /** - * Generate footnotes - */ - public function footnotes() { - $this->currentStyle = ''; - if (!empty($this->printedfootnotes)) { - foreach ($this->printedfootnotes as $element) { - $element->renderFootnote($this); - } - } - } - - /** - * Run the report. - */ - public function run() { - // Setting up the styles - echo '', PHP_EOL; - echo '
'; - echo '
'; - foreach ($this->headerElements as $element) { - if (is_object($element)) { - $element->render($this); - } elseif (is_string($element) && $element == 'footnotetexts') { - $this->footnotes(); - } elseif (is_string($element) && $element == 'addpage') { - $this->addPage(); - } - } - //-- body - echo '
'; - echo ''; - echo '
'; - $this->Y = 0; - $this->maxY = 0; - $this->runPageHeader(); - foreach ($this->bodyElements as $element) { - if (is_object($element)) { - $element->render($this); - } elseif (is_string($element) && $element == 'footnotetexts') { - $this->footnotes(); - } elseif (is_string($element) && $element == 'addpage') { - $this->addPage(); - } - } - //-- footer - echo '
'; - echo ''; - echo '
'; - echo '
'; - $this->Y = 0; - $this->X = 0; - $this->maxY = 0; - foreach ($this->footerElements as $element) { - if (is_object($element)) { - $element->render($this); - } elseif (is_string($element) && $element == 'footnotetexts') { - $this->footnotes(); - } elseif (is_string($element) && $element == 'addpage') { - $this->addPage(); - } - } - echo '
'; - echo ''; - echo '
'; - } - - /** - * Create a new Cell object - ReportHtml - * - * @param int $width cell width (expressed in points) - * @param int $height cell height (expressed in points) - * @param mixed $border Border style - * @param string $align Text alignement - * @param string $bgcolor Background color code - * @param string $style The name of the text style - * @param int $ln Indicates where the current position should go after the call - * @param mixed $top Y-position - * @param mixed $left X-position - * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. - * @param int $stretch Stretch carachter mode - * @param string $bocolor Border color - * @param string $tcolor Text color - * @param bool $reseth - * - * @return object ReportHtmlCell - */ - public function createCell($width, $height, $border, $align, $bgcolor, $style, $ln, $top, $left, $fill, $stretch, $bocolor, $tcolor, $reseth) { - return new ReportHtmlCell($width, $height, $border, $align, $bgcolor, $style, $ln, $top, $left, $fill, $stretch, $bocolor, $tcolor, $reseth); - } - - /** - * Create a text box. - * - * @param $width - * @param $height - * @param $border - * @param $bgcolor - * @param $newline - * @param $left - * @param $top - * @param $pagecheck - * @param $style - * @param $fill - * @param $padding - * @param $reseth - * - * @return ReportHtmlTextbox - */ - public function createTextBox($width, $height, $border, $bgcolor, $newline, $left, $top, $pagecheck, $style, $fill, $padding, $reseth) { - return new ReportHtmlTextbox($width, $height, $border, $bgcolor, $newline, $left, $top, $pagecheck, $style, $fill, $padding, $reseth); - } - - /** - * Create a text element. - * - * @param $style - * @param $color - * - * @return ReportHtmlText - */ - public function createText($style, $color) { - return new ReportHtmlText($style, $color); - } - - /** - * Create a footnote. - * - * @param string $style - * - * @return ReportHtmlFootnote - */ - public function createFootnote($style = '') { - return new ReportHtmlFootnote($style); - } - - /** - * Create a page header. - * - * @return ReportHtmlPageheader - */ - public function createPageHeader() { - return new ReportHtmlPageheader; - } - - /** - * Create an image. - * - * @param $file - * @param $x - * @param $y - * @param $w - * @param $h - * @param $align - * @param $ln - * - * @return ReportHtmlImage - */ - public function createImage($file, $x, $y, $w, $h, $align, $ln) { - return new ReportHtmlImage($file, $x, $y, $w, $h, $align, $ln); - } - - /** - * Create an image. - * - * @param MediaFile $media_file - * @param $x - * @param $y - * @param $w - * @param $h - * @param $align - * @param $ln - * - * @return ReportHtmlImage - */ - public function createImageFromObject(MediaFile $media_file, $x, $y, $w, $h, $align, $ln) { - return new ReportHtmlImage($media_file->imageUrl($w, $h, ''), $x, $y, $w, $h, $align, $ln); - } - - /** - * Create a line. - * - * @param $x1 - * @param $y1 - * @param $x2 - * @param $y2 - * - * @return ReportHtmlLine - */ - public function createLine($x1, $y1, $x2, $y2) { - return new ReportHtmlLine($x1, $y1, $x2, $y2); - } - - /** - * Create an HTML element. - * - * @param $tag - * @param $attrs - * - * @return ReportHtmlHtml - */ - public function createHTML($tag, $attrs) { - return new ReportHtmlHtml($tag, $attrs); - } - - /** - * Clear the Header - ReportHtml - */ - public function clearHeader() { - $this->headerElements = []; - } - - /** - * Update the Page Number and set a new Y if max Y is larger - ReportHtml - */ - public function addPage() { - $this->pageN++; - // Add a little margin to max Y "between pages" - $this->maxY += 10; - // If Y is still heigher by any reason... - if ($this->maxY < $this->Y) { - // ... update max Y - $this->maxY = $this->Y; - } // else update Y so that nothing will be overwritten, like images or cells... - else { - $this->Y = $this->maxY; - } - } - - /** - * Uppdate max Y to keep track it incase of a pagebreak - ReportHtml - * - * @param float $y - */ - public function addMaxY($y) { - if ($this->maxY < $y) { - $this->maxY = $y; - } - } - - /** - * Add a page header. - * - * @param $element - * - * @return int - */ - public function addPageHeader($element) { - $this->pageHeaderElements[] = $element; - - return count($this->headerElements) - 1; - } - - /** - * Checks the Footnote and numbers them - ReportHtml - * - * @param object $footnote - * - * @return bool false if not numbered before | object if already numbered - */ - public function checkFootnote($footnote) { - $ct = count($this->printedfootnotes); - $i = 0; - $val = $footnote->getValue(); - while ($i < $ct) { - if ($this->printedfootnotes[$i]->getValue() == $val) { - // If this footnote already exist then set up the numbers for this object - $footnote->setNum($i + 1); - $footnote->setAddlink($i + 1); - - return $this->printedfootnotes[$i]; - } - $i++; - } - // If this Footnote has not been set up yet - $footnote->setNum($ct + 1); - $footnote->setAddlink($ct + 1); - $this->printedfootnotes[] = $footnote; - - return false; - } - - /** - * Clear the Page Header - ReportHtml - */ - public function clearPageHeader() { - $this->pageHeaderElements = []; - } - - /** - * Count the number of lines - ReportHtml - * - * @param string $str - * - * @return int Number of lines. 0 if empty line - */ - public function countLines($str) { - if ($str == '') { - return 0; - } - - return (substr_count($str, "\n") + 1); - } - - /** - * Get the current style. - * - * @return string - */ - public function getCurrentStyle() { - return $this->currentStyle; - } - - /** - * Get the current style height. - * - * @return int - */ - public function getCurrentStyleHeight() { - if (empty($this->currentStyle)) { - return $this->defaultFontSize; - } - $style = $this->getStyle($this->currentStyle); - - return $style['size']; - } - - /** - * Get the current footnotes height. - * - * @param $cellWidth - * - * @return int - */ - public function getFootnotesHeight($cellWidth) { - $h = 0; - foreach ($this->printedfootnotes as $element) { - $h += $element->getFootnoteHeight($this, $cellWidth); - } - - return $h; - } - - /** - * Get the maximum width from current position to the margin - ReportHtml - * - * @return float - */ - public function getRemainingWidth() { - return $this->noMarginWidth - $this->X; - } - - /** - * Get the page height. - * - * @return float - */ - public function getPageHeight() { - return $this->pageh - $this->topmargin; - } - - /** - * Get the width of a string. - * - * @param $text - * - * @return int - */ - public function getStringWidth($text) { - $style = $this->getStyle($this->currentStyle); - - return mb_strlen($text) * ($style['size'] / 2); - } - - /** - * Get a text height in points - ReportHtml - * - * @param $str - * - * @return int - */ - public function getTextCellHeight($str) { - // Count the number of lines to calculate the height - $nl = $this->countLines($str); - // Calculate the cell height - return ceil(($this->getCurrentStyleHeight() * $this->cellHeightRatio) * $nl); - } - - /** - * Get the current X position - ReportHtml - * - * @return float - */ - public function getX() { - return $this->X; - } - - /** - * Get the current Y position - ReportHtml - * - * @return float - */ - public function getY() { - return $this->Y; - } - - /** - * Get the current page number - ReportHtml - * - * @return int - */ - public function pageNo() { - return $this->pageN; - } - - /** - * Set the current style. - * - * @param $s - */ - public function setCurrentStyle($s) { - $this->currentStyle = $s; - } - - /** - * Set the X position - ReportHtml - * - * @param float $x - */ - public function setX($x) { - $this->X = $x; - } - - /** - * Set the Y position - ReportHtml - * - * Also updates Max Y position - * - * @param float $y - */ - public function setY($y) { - $this->Y = $y; - if ($this->maxY < $y) { - $this->maxY = $y; - } - } - - /** - * Set the X and Y position - ReportHtml - * - * Also updates Max Y position - * - * @param float $x - * @param float $y - */ - public function setXy($x, $y) { - $this->setX($x); - $this->setY($y); - } - - /** - * Wrap text - ReportHtml - * - * @param string $str Text to wrap - * @param int $width Width in points the text has to fit into - * - * @return string - */ - public function textWrap($str, $width) { - // Calculate the line width - $lw = (int) ($width / ($this->getCurrentStyleHeight() / 2)); - // Wordwrap each line - $lines = explode("\n", $str); - // Line Feed counter - $lfct = count($lines); - $wraptext = ''; - foreach ($lines as $line) { - $wtext = FunctionsRtl::utf8WordWrap($line, $lw, "\n", true); - $wraptext .= $wtext; - // Add a new line as long as it’s not the last line - if ($lfct > 1) { - $wraptext .= "\n"; - } - $lfct--; - } - - return $wraptext; - } - - /** - * Write text - ReportHtml - * - * @param string $text Text to print - * @param string $color HTML RGB color code (Ex: #001122) - * @param bool $useclass - */ - public function write($text, $color = '', $useclass = true) { - $style = $this->getStyle($this->getCurrentStyle()); - $htmlcode = ''; - $htmlcode = str_replace(["\n", '> ', ' <'], ['
', '> ', ' <'], $htmlcode); - echo $htmlcode; - } +class ReportHtml extends ReportBase +{ + /** + * Cell padding + * + * @var int + */ + public $cPadding = 2; + + /** + * Cell height ratio + * + * @var float + */ + public $cellHeightRatio = 1.8; + + /** + * Current horizontal position + * + * @var float + */ + public $X = 0.0; + + /** + * Current vertical position + * + * @var float + */ + public $Y = 0.0; + + /** + * Currently used style name + * + * @var string + */ + public $currentStyle = ''; + + /** + * Page number counter + * + * @var int + */ + public $pageN = 1; + + /** + * Store the page width without left and right margins + * + * In HTML, we don't need this + * + * @var float + */ + public $noMarginWidth = 0.0; + + /** + * Last cell height + * + * @var float + */ + public $lastCellHeight = 0.0; + + /** + * LTR or RTL alignement; "left" on LTR, "right" on RTL + * Used in
+ * + * @var string + */ + public $alignRTL = 'left'; + + /** + * LTR or RTL entity + * + * @var string + */ + public $entityRTL = '‎'; + + /** + * Largest Font Height is used by TextBox etc. + * + * Use this to calculate a the text height. + * This makes sure that the text fits into the cell/box when different font sizes are used + * + * @var int + */ + public $largestFontHeight = 0; + + /** + * Keep track of the highest Y position + * + * Used with Header div / Body div / Footer div / "addpage" / The bottom of the last image etc. + * + * @var float + */ + public $maxY = 0; + + /** @var ReportBaseElement[] Array of elements in the header */ + public $headerElements = []; + + /** @var ReportBaseElement[] Array of elements in the page header */ + public $pageHeaderElements = []; + + /** @var ReportBaseElement[] Array of elements in the footer */ + public $footerElements = []; + + /** @var ReportBaseElement[] Array of elements in the body */ + public $bodyElements = []; + + /** @var ReportBaseFootnote[] Array of elements in the footer notes */ + public $printedfootnotes = []; + + /** + * HTML Setup - ReportHtml + */ + public function setup() + { + parent::setup(); + + // Setting up the correct dimensions if Portrait (default) or Landscape + if ($this->orientation == 'landscape') { + $tmpw = $this->pagew; + $this->pagew = $this->pageh; + $this->pageh = $tmpw; + } + // Store the pagewidth without margins + $this->noMarginWidth = (int)($this->pagew - $this->leftmargin - $this->rightmargin); + // If RTL + if ($this->rtl) { + $this->alignRTL = 'right'; + $this->entityRTL = '‏'; + } + // Change the default HTML font name + $this->defaultFont = 'Arial'; + + if ($this->showGenText) { + // The default style name for Generated by.... is 'genby' + $element = new ReportHtmlCell(0, 10, 0, 'C', '', 'genby', 1, '.', '.', 0, 0, '', '', true); + $element->addText($this->generatedby); + $element->setUrl(parent::WT_URL); + $this->footerElements[] = $element; + } + } + + /** + * Add an element. + * + * @param $element + */ + public function addElement($element) + { + if ($this->processing == 'B') { + $this->bodyElements[] = $element; + } elseif ($this->processing == 'H') { + $this->headerElements[] = $element; + } elseif ($this->processing == 'F') { + $this->footerElements[] = $element; + } + } + + /** + * Generate the page header + */ + public function runPageHeader() + { + foreach ($this->pageHeaderElements as $element) { + if (is_object($element)) { + $element->render($this); + } elseif (is_string($element) && $element == 'footnotetexts') { + $this->footnotes(); + } elseif (is_string($element) && $element == 'addpage') { + $this->addPage(); + } + } + } + + /** + * Generate footnotes + */ + public function footnotes() + { + $this->currentStyle = ''; + if (!empty($this->printedfootnotes)) { + foreach ($this->printedfootnotes as $element) { + $element->renderFootnote($this); + } + } + } + + /** + * Run the report. + */ + public function run() + { + // Setting up the styles + echo '', PHP_EOL; + echo '
'; + echo '
'; + foreach ($this->headerElements as $element) { + if (is_object($element)) { + $element->render($this); + } elseif (is_string($element) && $element == 'footnotetexts') { + $this->footnotes(); + } elseif (is_string($element) && $element == 'addpage') { + $this->addPage(); + } + } + //-- body + echo '
'; + echo ''; + echo '
'; + $this->Y = 0; + $this->maxY = 0; + $this->runPageHeader(); + foreach ($this->bodyElements as $element) { + if (is_object($element)) { + $element->render($this); + } elseif (is_string($element) && $element == 'footnotetexts') { + $this->footnotes(); + } elseif (is_string($element) && $element == 'addpage') { + $this->addPage(); + } + } + //-- footer + echo '
'; + echo ''; + echo '
'; + echo '
'; + $this->Y = 0; + $this->X = 0; + $this->maxY = 0; + foreach ($this->footerElements as $element) { + if (is_object($element)) { + $element->render($this); + } elseif (is_string($element) && $element == 'footnotetexts') { + $this->footnotes(); + } elseif (is_string($element) && $element == 'addpage') { + $this->addPage(); + } + } + echo '
'; + echo ''; + echo '
'; + } + + /** + * Create a new Cell object - ReportHtml + * + * @param int $width cell width (expressed in points) + * @param int $height cell height (expressed in points) + * @param mixed $border Border style + * @param string $align Text alignement + * @param string $bgcolor Background color code + * @param string $style The name of the text style + * @param int $ln Indicates where the current position should go after the call + * @param mixed $top Y-position + * @param mixed $left X-position + * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. + * @param int $stretch Stretch carachter mode + * @param string $bocolor Border color + * @param string $tcolor Text color + * @param bool $reseth + * + * @return object ReportHtmlCell + */ + public function createCell($width, $height, $border, $align, $bgcolor, $style, $ln, $top, $left, $fill, $stretch, $bocolor, $tcolor, $reseth) + { + return new ReportHtmlCell($width, $height, $border, $align, $bgcolor, $style, $ln, $top, $left, $fill, $stretch, $bocolor, $tcolor, $reseth); + } + + /** + * Create a text box. + * + * @param $width + * @param $height + * @param $border + * @param $bgcolor + * @param $newline + * @param $left + * @param $top + * @param $pagecheck + * @param $style + * @param $fill + * @param $padding + * @param $reseth + * + * @return ReportHtmlTextbox + */ + public function createTextBox($width, $height, $border, $bgcolor, $newline, $left, $top, $pagecheck, $style, $fill, $padding, $reseth) + { + return new ReportHtmlTextbox($width, $height, $border, $bgcolor, $newline, $left, $top, $pagecheck, $style, $fill, $padding, $reseth); + } + + /** + * Create a text element. + * + * @param $style + * @param $color + * + * @return ReportHtmlText + */ + public function createText($style, $color) + { + return new ReportHtmlText($style, $color); + } + + /** + * Create a footnote. + * + * @param string $style + * + * @return ReportHtmlFootnote + */ + public function createFootnote($style = '') + { + return new ReportHtmlFootnote($style); + } + + /** + * Create a page header. + * + * @return ReportHtmlPageheader + */ + public function createPageHeader() + { + return new ReportHtmlPageheader; + } + + /** + * Create an image. + * + * @param $file + * @param $x + * @param $y + * @param $w + * @param $h + * @param $align + * @param $ln + * + * @return ReportHtmlImage + */ + public function createImage($file, $x, $y, $w, $h, $align, $ln) + { + return new ReportHtmlImage($file, $x, $y, $w, $h, $align, $ln); + } + + /** + * Create an image. + * + * @param MediaFile $media_file + * @param $x + * @param $y + * @param $w + * @param $h + * @param $align + * @param $ln + * + * @return ReportHtmlImage + */ + public function createImageFromObject(MediaFile $media_file, $x, $y, $w, $h, $align, $ln) + { + return new ReportHtmlImage($media_file->imageUrl($w, $h, ''), $x, $y, $w, $h, $align, $ln); + } + + /** + * Create a line. + * + * @param $x1 + * @param $y1 + * @param $x2 + * @param $y2 + * + * @return ReportHtmlLine + */ + public function createLine($x1, $y1, $x2, $y2) + { + return new ReportHtmlLine($x1, $y1, $x2, $y2); + } + + /** + * Create an HTML element. + * + * @param $tag + * @param $attrs + * + * @return ReportHtmlHtml + */ + public function createHTML($tag, $attrs) + { + return new ReportHtmlHtml($tag, $attrs); + } + + /** + * Clear the Header - ReportHtml + */ + public function clearHeader() + { + $this->headerElements = []; + } + + /** + * Update the Page Number and set a new Y if max Y is larger - ReportHtml + */ + public function addPage() + { + $this->pageN++; + // Add a little margin to max Y "between pages" + $this->maxY += 10; + // If Y is still heigher by any reason... + if ($this->maxY < $this->Y) { + // ... update max Y + $this->maxY = $this->Y; + } // else update Y so that nothing will be overwritten, like images or cells... + else { + $this->Y = $this->maxY; + } + } + + /** + * Uppdate max Y to keep track it incase of a pagebreak - ReportHtml + * + * @param float $y + */ + public function addMaxY($y) + { + if ($this->maxY < $y) { + $this->maxY = $y; + } + } + + /** + * Add a page header. + * + * @param $element + * + * @return int + */ + public function addPageHeader($element) + { + $this->pageHeaderElements[] = $element; + + return count($this->headerElements) - 1; + } + + /** + * Checks the Footnote and numbers them - ReportHtml + * + * @param object $footnote + * + * @return bool false if not numbered before | object if already numbered + */ + public function checkFootnote($footnote) + { + $ct = count($this->printedfootnotes); + $i = 0; + $val = $footnote->getValue(); + while ($i < $ct) { + if ($this->printedfootnotes[$i]->getValue() == $val) { + // If this footnote already exist then set up the numbers for this object + $footnote->setNum($i + 1); + $footnote->setAddlink($i + 1); + + return $this->printedfootnotes[$i]; + } + $i++; + } + // If this Footnote has not been set up yet + $footnote->setNum($ct + 1); + $footnote->setAddlink($ct + 1); + $this->printedfootnotes[] = $footnote; + + return false; + } + + /** + * Clear the Page Header - ReportHtml + */ + public function clearPageHeader() + { + $this->pageHeaderElements = []; + } + + /** + * Count the number of lines - ReportHtml + * + * @param string $str + * + * @return int Number of lines. 0 if empty line + */ + public function countLines($str) + { + if ($str == '') { + return 0; + } + + return (substr_count($str, "\n") + 1); + } + + /** + * Get the current style. + * + * @return string + */ + public function getCurrentStyle() + { + return $this->currentStyle; + } + + /** + * Get the current style height. + * + * @return int + */ + public function getCurrentStyleHeight() + { + if (empty($this->currentStyle)) { + return $this->defaultFontSize; + } + $style = $this->getStyle($this->currentStyle); + + return $style['size']; + } + + /** + * Get the current footnotes height. + * + * @param $cellWidth + * + * @return int + */ + public function getFootnotesHeight($cellWidth) + { + $h = 0; + foreach ($this->printedfootnotes as $element) { + $h += $element->getFootnoteHeight($this, $cellWidth); + } + + return $h; + } + + /** + * Get the maximum width from current position to the margin - ReportHtml + * + * @return float + */ + public function getRemainingWidth() + { + return $this->noMarginWidth - $this->X; + } + + /** + * Get the page height. + * + * @return float + */ + public function getPageHeight() + { + return $this->pageh - $this->topmargin; + } + + /** + * Get the width of a string. + * + * @param $text + * + * @return int + */ + public function getStringWidth($text) + { + $style = $this->getStyle($this->currentStyle); + + return mb_strlen($text) * ($style['size'] / 2); + } + + /** + * Get a text height in points - ReportHtml + * + * @param $str + * + * @return int + */ + public function getTextCellHeight($str) + { + // Count the number of lines to calculate the height + $nl = $this->countLines($str); + + // Calculate the cell height + return ceil(($this->getCurrentStyleHeight() * $this->cellHeightRatio) * $nl); + } + + /** + * Get the current X position - ReportHtml + * + * @return float + */ + public function getX() + { + return $this->X; + } + + /** + * Get the current Y position - ReportHtml + * + * @return float + */ + public function getY() + { + return $this->Y; + } + + /** + * Get the current page number - ReportHtml + * + * @return int + */ + public function pageNo() + { + return $this->pageN; + } + + /** + * Set the current style. + * + * @param $s + */ + public function setCurrentStyle($s) + { + $this->currentStyle = $s; + } + + /** + * Set the X position - ReportHtml + * + * @param float $x + */ + public function setX($x) + { + $this->X = $x; + } + + /** + * Set the Y position - ReportHtml + * + * Also updates Max Y position + * + * @param float $y + */ + public function setY($y) + { + $this->Y = $y; + if ($this->maxY < $y) { + $this->maxY = $y; + } + } + + /** + * Set the X and Y position - ReportHtml + * + * Also updates Max Y position + * + * @param float $x + * @param float $y + */ + public function setXy($x, $y) + { + $this->setX($x); + $this->setY($y); + } + + /** + * Wrap text - ReportHtml + * + * @param string $str Text to wrap + * @param int $width Width in points the text has to fit into + * + * @return string + */ + public function textWrap($str, $width) + { + // Calculate the line width + $lw = (int)($width / ($this->getCurrentStyleHeight() / 2)); + // Wordwrap each line + $lines = explode("\n", $str); + // Line Feed counter + $lfct = count($lines); + $wraptext = ''; + foreach ($lines as $line) { + $wtext = FunctionsRtl::utf8WordWrap($line, $lw, "\n", true); + $wraptext .= $wtext; + // Add a new line as long as it’s not the last line + if ($lfct > 1) { + $wraptext .= "\n"; + } + $lfct--; + } + + return $wraptext; + } + + /** + * Write text - ReportHtml + * + * @param string $text Text to print + * @param string $color HTML RGB color code (Ex: #001122) + * @param bool $useclass + */ + public function write($text, $color = '', $useclass = true) + { + $style = $this->getStyle($this->getCurrentStyle()); + $htmlcode = ''; + $htmlcode = str_replace([ + "\n", + '> ', + ' <', + ], [ + '
', + '> ', + ' <', + ], $htmlcode); + echo $htmlcode; + } } diff --git a/app/Report/ReportHtmlCell.php b/app/Report/ReportHtmlCell.php index b066f3867a..4ba66ca0b2 100644 --- a/app/Report/ReportHtmlCell.php +++ b/app/Report/ReportHtmlCell.php @@ -18,177 +18,185 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportHtmlCell */ -class ReportHtmlCell extends ReportBaseCell { - /** - * HTML Cell renderer - * - * @param ReportHtml $renderer - */ - public function render($renderer) { - if (strpos($this->text, '{{:ptp:}}') !== false) { - return; - } - $temptext = str_replace('#PAGENUM#', $renderer->pageNo(), $this->text); - // underline «title» part of Source item - $temptext = str_replace(['«', '»'], ['', ''], $temptext); +class ReportHtmlCell extends ReportBaseCell +{ + /** + * HTML Cell renderer + * + * @param ReportHtml $renderer + */ + public function render($renderer) + { + if (strpos($this->text, '{{:ptp:}}') !== false) { + return; + } + $temptext = str_replace('#PAGENUM#', $renderer->pageNo(), $this->text); + // underline «title» part of Source item + $temptext = str_replace([ + '«', + '»', + ], [ + '', + '', + ], $temptext); - // Setup the style name - if ($renderer->getCurrentStyle() != $this->styleName) { - $renderer->setCurrentStyle($this->styleName); - } + // Setup the style name + if ($renderer->getCurrentStyle() != $this->styleName) { + $renderer->setCurrentStyle($this->styleName); + } - // If (Future-feature-enable/disable cell padding) - $cP = $renderer->cPadding; + // If (Future-feature-enable/disable cell padding) + $cP = $renderer->cPadding; - // Adjust the positions - if ($this->left == '.') { - $this->left = $renderer->getX(); - } else { - $renderer->setX($this->left); - } + // Adjust the positions + if ($this->left == '.') { + $this->left = $renderer->getX(); + } else { + $renderer->setX($this->left); + } - if ($this->top == '.') { - $this->top = $renderer->getY(); - } else { - $renderer->setY($this->top); - } + if ($this->top == '.') { + $this->top = $renderer->getY(); + } else { + $renderer->setY($this->top); + } - // Start collecting the HTML code - echo '
styleName, '" style="position:absolute;top:', $this->top, 'pt;'; + // Use Cell around padding to support RTL also + echo 'padding:', $cP, 'pt;'; + // LTR (left) or RTL (right) + echo $renderer->alignRTL, ':', $this->left, 'pt;'; + // Background color + if (!empty($this->bgcolor)) { + echo 'background-color:', $this->bgcolor, ';'; + } + // Border setup + $bpixX = 0; + $bpixY = 0; + if (!empty($this->border)) { + // Border all around + if ($this->border == 1) { + echo ' border:solid '; + if (!empty($this->bocolor)) { + echo $this->bocolor; + } else { + echo 'black'; + } + echo ' 1pt;'; + $bpixX = 1; + $bpixY = 1; + } else { + if (stripos($this->border, 'T') !== false) { + echo ' border-top:solid '; + if (!empty($this->bocolor)) { + echo $this->bocolor; + } else { + echo 'black'; + } + echo ' 1pt;'; + $bpixY = 1; + } + if (stripos($this->border, 'B') !== false) { + echo ' border-bottom:solid '; + if (!empty($this->bocolor)) { + echo $this->bocolor; + } else { + echo 'black'; + } + echo ' 1pt;'; + $bpixY = 1; + } + if (stripos($this->border, 'R') !== false) { + echo ' border-right:solid '; + if (!empty($this->bocolor)) { + echo $this->bocolor; + } else { + echo 'black'; + } + echo ' 1pt;'; + $bpixX = 1; + } + if (stripos($this->border, 'L') !== false) { + echo ' border-left:solid '; + if (!empty($this->bocolor)) { + echo $this->bocolor; + } else { + echo 'black'; + } + echo ' 1pt;'; + $bpixX = 1; + } + } + } + // Check the width if set to page wide OR set by xml to larger then page wide + if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) { + $this->width = $renderer->getRemainingWidth(); + } + // We have to calculate a different width for the padding, counting on both side + $cW = $this->width - ($cP * 2); - // If there is any text - if (!empty($temptext)) { - // Wrap the text - $temptext = $renderer->textWrap($temptext, $cW); - $tmph = $renderer->getTextCellHeight($temptext); - // Add some cell padding - $this->height += $cP; - if ($tmph > $this->height) { - $this->height = $tmph; - } - } - // Check the last cell height and ajust with the current cell height - if ($renderer->lastCellHeight > $this->height) { - $this->height = $renderer->lastCellHeight; - } - echo ' width:', $cW - $bpixX, 'pt;height:', $this->height - $bpixY, 'pt;'; + // If there is any text + if (!empty($temptext)) { + // Wrap the text + $temptext = $renderer->textWrap($temptext, $cW); + $tmph = $renderer->getTextCellHeight($temptext); + // Add some cell padding + $this->height += $cP; + if ($tmph > $this->height) { + $this->height = $tmph; + } + } + // Check the last cell height and ajust with the current cell height + if ($renderer->lastCellHeight > $this->height) { + $this->height = $renderer->lastCellHeight; + } + echo ' width:', $cW - $bpixX, 'pt;height:', $this->height - $bpixY, 'pt;'; - // Text alignment - switch ($this->align) { - case 'C': - echo ' text-align:center;'; - break; - case 'L': - echo ' text-align:left;'; - break; - case 'R': - echo ' text-align:right;'; - break; - } + // Text alignment + switch ($this->align) { + case 'C': + echo ' text-align:center;'; + break; + case 'L': + echo ' text-align:left;'; + break; + case 'R': + echo ' text-align:right;'; + break; + } - // Print the collected HTML code - echo '">'; + // Print the collected HTML code + echo '">'; - // Print URL - if (!empty($this->url)) { - echo ''; - } - // Print any text if exists - if (!empty($temptext)) { - $renderer->write($temptext, $this->tcolor, false); - } - if (!empty($this->url)) { - echo ''; - } - // Finish the cell printing and start to clean up - echo "
\n"; - // Where to place the next position - // -> Next to this cell in the same line - if ($this->newline == 0) { - $renderer->setXy($this->left + $this->width, $this->top); - $renderer->lastCellHeight = $this->height; - } // -> On a new line at the margin - Default - elseif ($this->newline == 1) { - $renderer->setXy(0, $renderer->getY() + $this->height + ($cP * 2)); - // Reset the last cell height for the next line - $renderer->lastCellHeight = 0; - } // -> On a new line at the end of this cell - elseif ($this->newline == 2) { - $renderer->setXy($renderer->getX() + $this->width, $renderer->getY() + $this->height + ($cP * 2)); - // Reset the last cell height for the next line - $renderer->lastCellHeight = 0; - } - } + // Print URL + if (!empty($this->url)) { + echo ''; + } + // Print any text if exists + if (!empty($temptext)) { + $renderer->write($temptext, $this->tcolor, false); + } + if (!empty($this->url)) { + echo ''; + } + // Finish the cell printing and start to clean up + echo "
\n"; + // Where to place the next position + // -> Next to this cell in the same line + if ($this->newline == 0) { + $renderer->setXy($this->left + $this->width, $this->top); + $renderer->lastCellHeight = $this->height; + } // -> On a new line at the margin - Default + elseif ($this->newline == 1) { + $renderer->setXy(0, $renderer->getY() + $this->height + ($cP * 2)); + // Reset the last cell height for the next line + $renderer->lastCellHeight = 0; + } // -> On a new line at the end of this cell + elseif ($this->newline == 2) { + $renderer->setXy($renderer->getX() + $this->width, $renderer->getY() + $this->height + ($cP * 2)); + // Reset the last cell height for the next line + $renderer->lastCellHeight = 0; + } + } } diff --git a/app/Report/ReportHtmlFootnote.php b/app/Report/ReportHtmlFootnote.php index 5a000b1f97..596580fca0 100644 --- a/app/Report/ReportHtmlFootnote.php +++ b/app/Report/ReportHtmlFootnote.php @@ -18,150 +18,169 @@ namespace Fisharebest\Webtrees\Report; /** * class ReportHtmlFootnote */ -class ReportHtmlFootnote extends ReportBaseFootnote { - /** - * HTML Footnotes number renderer - * - * @param ReportHtml $renderer - */ - public function render($renderer) { - $renderer->setCurrentStyle('footnotenum'); - echo ''; - $renderer->write($renderer->entityRTL . $this->num); - echo "\n"; - } +class ReportHtmlFootnote extends ReportBaseFootnote +{ + /** + * HTML Footnotes number renderer + * + * @param ReportHtml $renderer + */ + public function render($renderer) + { + $renderer->setCurrentStyle('footnotenum'); + echo ''; + $renderer->write($renderer->entityRTL . $this->num); + echo "\n"; + } - /** - * Write the Footnote text - * Uses style name "footnote" by default - * - * @param ReportHtml $html - */ - public function renderFootnote($html) { - if ($html->getCurrentStyle() != $this->styleName) { - $html->setCurrentStyle($this->styleName); - } + /** + * Write the Footnote text + * Uses style name "footnote" by default + * + * @param ReportHtml $html + */ + public function renderFootnote($html) + { + if ($html->getCurrentStyle() != $this->styleName) { + $html->setCurrentStyle($this->styleName); + } - $temptext = str_replace('#PAGENUM#', $html->pageNo(), $this->text); - // underline «title» part of Source item - $temptext = str_replace(['«', '»'], ['', ''], $temptext); - echo "\n
num, '">'; - $html->write($this->num . '. ' . $temptext); - echo '
'; + $temptext = str_replace('#PAGENUM#', $html->pageNo(), $this->text); + // underline «title» part of Source item + $temptext = str_replace([ + '«', + '»', + ], [ + '', + '', + ], $temptext); + echo "\n
num, '">'; + $html->write($this->num . '. ' . $temptext); + echo '
'; - $html->setXy(0, $html->getY() + $this->getFootnoteHeight($html)); - } + $html->setXy(0, $html->getY() + $this->getFootnoteHeight($html)); + } - /** - * Calculates the Footnotes height - * - * @param ReportHtml $html - * @param int $cellWidth The width of the cell to use it for text wraping - * - * @return int Footnote height in points - */ - public function getFootnoteHeight($html, $cellWidth = 0) { - if ($html->getCurrentStyle() != $this->styleName) { - $html->setCurrentStyle($this->styleName); - } + /** + * Calculates the Footnotes height + * + * @param ReportHtml $html + * @param int $cellWidth The width of the cell to use it for text wraping + * + * @return int Footnote height in points + */ + public function getFootnoteHeight($html, $cellWidth = 0) + { + if ($html->getCurrentStyle() != $this->styleName) { + $html->setCurrentStyle($this->styleName); + } - if ($cellWidth > 0) { - $this->text = $html->textWrap($this->text, $cellWidth); - } - $this->text = $this->text . "\n\n"; - $ct = substr_count($this->text, "\n"); - $fsize = $html->getCurrentStyleHeight(); + if ($cellWidth > 0) { + $this->text = $html->textWrap($this->text, $cellWidth); + } + $this->text = $this->text . "\n\n"; + $ct = substr_count($this->text, "\n"); + $fsize = $html->getCurrentStyleHeight(); - return ($fsize * $ct) * $html->cellHeightRatio; - } + return ($fsize * $ct) * $html->cellHeightRatio; + } - /** - * Get the width of text - * Breaks up a text into lines if needed - * - * @param ReportHtml $html - * - * @return array - */ - public function getWidth($html) { - // Setup the style name - $html->setCurrentStyle('footnotenum'); + /** + * Get the width of text + * Breaks up a text into lines if needed + * + * @param ReportHtml $html + * + * @return array + */ + public function getWidth($html) + { + // Setup the style name + $html->setCurrentStyle('footnotenum'); - // Check for the largest font size in the box - $fsize = $html->getCurrentStyleHeight(); - if ($fsize > $html->largestFontHeight) { - $html->largestFontHeight = $fsize; - } + // Check for the largest font size in the box + $fsize = $html->getCurrentStyleHeight(); + if ($fsize > $html->largestFontHeight) { + $html->largestFontHeight = $fsize; + } - // Returns the Object if already numbered else false - if (empty($this->num)) { - $html->checkFootnote($this); - } + // Returns the Object if already numbered else false + if (empty($this->num)) { + $html->checkFootnote($this); + } - // Get the line width for the text in points + a little margin - $lw = $html->getStringWidth($this->numText); - // Line Feed counter - Number of lines in the text - $lfct = $html->countLines($this->numText); - // If there is still remaining wrap width... - if ($this->wrapWidthRemaining > 0) { - // Check with line counter too! - if ($lw >= $this->wrapWidthRemaining || $lfct > 1) { - $newtext = ''; - $wrapWidthRemaining = $this->wrapWidthRemaining; - $lines = explode("\n", $this->numText); - // Go throught the text line by line - foreach ($lines as $line) { - // Line width in points + a little margin - $lw = $html->getStringWidth($line); - // If the line has to be wraped - if ($lw > $wrapWidthRemaining) { - $words = explode(' ', $line); - $addspace = count($words); - $lw = 0; - foreach ($words as $word) { - $addspace--; - $lw += $html->getStringWidth($word . ' '); - if ($lw <= $wrapWidthRemaining) { - $newtext .= $word; - if ($addspace != 0) { - $newtext .= ' '; - } - } else { - $lw = $html->getStringWidth($word . ' '); - $newtext .= "\n$word"; - if ($addspace != 0) { - $newtext .= ' '; - } - // Reset the wrap width to the cell width - $wrapWidthRemaining = $this->wrapWidthCell; - } - } - } else { - $newtext .= $line; - } - // Check the Line Feed counter - if ($lfct > 1) { - // Add a new line feed as long as it’s not the last line - $newtext .= "\n"; - // Reset the line width - $lw = 0; - // Reset the wrap width to the cell width - $wrapWidthRemaining = $this->wrapWidthCell; - } - $lfct--; - } - $this->numText = $newtext; - $lfct = substr_count($this->numText, "\n"); + // Get the line width for the text in points + a little margin + $lw = $html->getStringWidth($this->numText); + // Line Feed counter - Number of lines in the text + $lfct = $html->countLines($this->numText); + // If there is still remaining wrap width... + if ($this->wrapWidthRemaining > 0) { + // Check with line counter too! + if ($lw >= $this->wrapWidthRemaining || $lfct > 1) { + $newtext = ''; + $wrapWidthRemaining = $this->wrapWidthRemaining; + $lines = explode("\n", $this->numText); + // Go throught the text line by line + foreach ($lines as $line) { + // Line width in points + a little margin + $lw = $html->getStringWidth($line); + // If the line has to be wraped + if ($lw > $wrapWidthRemaining) { + $words = explode(' ', $line); + $addspace = count($words); + $lw = 0; + foreach ($words as $word) { + $addspace--; + $lw += $html->getStringWidth($word . ' '); + if ($lw <= $wrapWidthRemaining) { + $newtext .= $word; + if ($addspace != 0) { + $newtext .= ' '; + } + } else { + $lw = $html->getStringWidth($word . ' '); + $newtext .= "\n$word"; + if ($addspace != 0) { + $newtext .= ' '; + } + // Reset the wrap width to the cell width + $wrapWidthRemaining = $this->wrapWidthCell; + } + } + } else { + $newtext .= $line; + } + // Check the Line Feed counter + if ($lfct > 1) { + // Add a new line feed as long as it’s not the last line + $newtext .= "\n"; + // Reset the line width + $lw = 0; + // Reset the wrap width to the cell width + $wrapWidthRemaining = $this->wrapWidthCell; + } + $lfct--; + } + $this->numText = $newtext; + $lfct = substr_count($this->numText, "\n"); - return [$lw, 1, $lfct]; - } - } - $l = 0; - $lfct = substr_count($this->numText, "\n"); - if ($lfct > 0) { - $l = 2; - } + return [ + $lw, + 1, + $lfct, + ]; + } + } + $l = 0; + $lfct = substr_count($this->numText, "\n"); + if ($lfct > 0) { + $l = 2; + } - return [$lw, $l, $lfct]; - } + return [ + $lw, + $l, + $lfct, + ]; + } } diff --git a/app/Report/ReportHtmlHtml.php b/app/Report/ReportHtmlHtml.php index 4dbdaa2aca..025dfce202 100644 --- a/app/Report/ReportHtmlHtml.php +++ b/app/Report/ReportHtmlHtml.php @@ -18,52 +18,54 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportHtmlHtml */ -class ReportHtmlHtml extends ReportBaseHtml { - /** - * Render the elements. - * - * @param ReportHtml $renderer - * @param bool $sub - * @param bool $inat - * - * @return string - */ - public function render($renderer, $sub = false, $inat = true) { - if (!empty($this->attrs['wt_style'])) { - $renderer->setCurrentStyle($this->attrs['wt_style']); - } +class ReportHtmlHtml extends ReportBaseHtml +{ + /** + * Render the elements. + * + * @param ReportHtml $renderer + * @param bool $sub + * @param bool $inat + * + * @return string + */ + public function render($renderer, $sub = false, $inat = true) + { + if (!empty($this->attrs['wt_style'])) { + $renderer->setCurrentStyle($this->attrs['wt_style']); + } - $this->text = $this->getStart() . $this->text; - foreach ($this->elements as $element) { - if (is_string($element) && $element == 'footnotetexts') { - $renderer->footnotes(); - } elseif (is_string($element) && $element == 'addpage') { - $renderer->addPage(); - } elseif ($element instanceof ReportBaseHtml) { - $element->render($renderer, true, false); - } else { - $element->render($renderer); - } - } - $this->text .= $this->getEnd(); - if ($sub) { - return $this->text; - } + $this->text = $this->getStart() . $this->text; + foreach ($this->elements as $element) { + if (is_string($element) && $element == 'footnotetexts') { + $renderer->footnotes(); + } elseif (is_string($element) && $element == 'addpage') { + $renderer->addPage(); + } elseif ($element instanceof ReportBaseHtml) { + $element->render($renderer, true, false); + } else { + $element->render($renderer); + } + } + $this->text .= $this->getEnd(); + if ($sub) { + return $this->text; + } - // If not called by an other attribute - if ($inat) { - $startX = $renderer->getX(); - $startY = $renderer->getY(); - $width = $renderer->getRemainingWidth(); - echo '
'; - $startY += $renderer->getCurrentStyleHeight() + 2; - $renderer->setY($startY); - } + // If not called by an other attribute + if ($inat) { + $startX = $renderer->getX(); + $startY = $renderer->getY(); + $width = $renderer->getRemainingWidth(); + echo '
'; + $startY += $renderer->getCurrentStyleHeight() + 2; + $renderer->setY($startY); + } - echo $this->text; + echo $this->text; - if ($inat) { - echo "
\n"; - } - } + if ($inat) { + echo "
\n"; + } + } } diff --git a/app/Report/ReportHtmlImage.php b/app/Report/ReportHtmlImage.php index 871a5b7f12..03b47392d0 100644 --- a/app/Report/ReportHtmlImage.php +++ b/app/Report/ReportHtmlImage.php @@ -18,69 +18,72 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportHtmlImage */ -class ReportHtmlImage extends ReportBaseImage { - /** - * Image renderer - * - * @param ReportHtml $renderer - */ - public function render($renderer) { - global $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright; +class ReportHtmlImage extends ReportBaseImage +{ + /** + * Image renderer + * + * @param ReportHtml $renderer + */ + public function render($renderer) + { + global $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright; - // Get the current positions - if ($this->x == '.') { - $this->x = $renderer->getX(); - } - if ($this->y == '.') { - //-- first check for a collision with the last picture - if (isset($lastpicbottom)) { - if (($renderer->pageNo() == $lastpicpage) && ($lastpicbottom >= $renderer->getY()) && ($this->x >= $lastpicleft) && ($this->x <= $lastpicright)) { - $renderer->setY($lastpicbottom + ($renderer->cPadding * 2)); - } - } - $this->y = $renderer->getY(); - } + // Get the current positions + if ($this->x == '.') { + $this->x = $renderer->getX(); + } + if ($this->y == '.') { + //-- first check for a collision with the last picture + if (isset($lastpicbottom)) { + if (($renderer->pageNo() == $lastpicpage) && ($lastpicbottom >= $renderer->getY()) && ($this->x >= $lastpicleft) && ($this->x <= $lastpicright)) { + $renderer->setY($lastpicbottom + ($renderer->cPadding * 2)); + } + } + $this->y = $renderer->getY(); + } - // Image alignment - switch ($this->align) { - case 'L': - echo '
\n"; - echo '\"\"\n
\n"; - break; - case 'C': - echo '
\n"; - echo '\"\"\n
\n"; - break; - case 'R': - echo '
\n"; - echo '\"\"\n
\n"; - break; - default: - echo '\"\"\n"; - } + // Image alignment + switch ($this->align) { + case 'L': + echo '
\n"; + echo '\"\"\n
\n"; + break; + case 'C': + echo '
\n"; + echo '\"\"\n
\n"; + break; + case 'R': + echo '
\n"; + echo '\"\"\n
\n"; + break; + default: + echo '\"\"\n"; + } - $lastpicpage = $renderer->pageNo(); - $lastpicleft = $this->x; - $lastpicright = $this->x + $this->width; - $lastpicbottom = $this->y + $this->height; - // Setup for the next line - if ($this->line == 'N') { - $renderer->setY($lastpicbottom); - } - // Keep max Y updated - $renderer->addMaxY($lastpicbottom); - } + $lastpicpage = $renderer->pageNo(); + $lastpicleft = $this->x; + $lastpicright = $this->x + $this->width; + $lastpicbottom = $this->y + $this->height; + // Setup for the next line + if ($this->line == 'N') { + $renderer->setY($lastpicbottom); + } + // Keep max Y updated + $renderer->addMaxY($lastpicbottom); + } - /** - * Get the image height - * This would be called from the TextBox only for multiple images - * so we add a bit bottom space between the images - * - * @param ReportHtml $html - * - * @return float - */ - public function getHeight($html) { - return $this->height + ($html->cPadding * 2); - } + /** + * Get the image height + * This would be called from the TextBox only for multiple images + * so we add a bit bottom space between the images + * + * @param ReportHtml $html + * + * @return float + */ + public function getHeight($html) + { + return $this->height + ($html->cPadding * 2); + } } diff --git a/app/Report/ReportHtmlLine.php b/app/Report/ReportHtmlLine.php index f9b21ce43c..727f40f630 100644 --- a/app/Report/ReportHtmlLine.php +++ b/app/Report/ReportHtmlLine.php @@ -18,36 +18,38 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportHtmlLine */ -class ReportHtmlLine extends ReportBaseLine { - /** - * HTML line renderer - * - * @param ReportHtml $renderer - */ - public function render($renderer) { - if ($this->x1 == '.') { - $this->x1 = $renderer->getX(); - } - if ($this->y1 == '.') { - $this->y1 = $renderer->getY(); - } - if ($this->x2 == '.') { - $this->x2 = $renderer->getRemainingWidth(); - } - if ($this->y2 == '.') { - $this->y2 = $renderer->getY(); - } - // Vertical line - if ($this->x1 == $this->x2) { - echo '
\n"; - } - // Horizontal line - if ($this->y1 == $this->y2) { - echo '
\n"; - } - // Keep max Y updated - // One or the other will be higher... lasy mans way... - $renderer->addMaxY($this->y1); - $renderer->addMaxY($this->y2); - } +class ReportHtmlLine extends ReportBaseLine +{ + /** + * HTML line renderer + * + * @param ReportHtml $renderer + */ + public function render($renderer) + { + if ($this->x1 == '.') { + $this->x1 = $renderer->getX(); + } + if ($this->y1 == '.') { + $this->y1 = $renderer->getY(); + } + if ($this->x2 == '.') { + $this->x2 = $renderer->getRemainingWidth(); + } + if ($this->y2 == '.') { + $this->y2 = $renderer->getY(); + } + // Vertical line + if ($this->x1 == $this->x2) { + echo '
\n"; + } + // Horizontal line + if ($this->y1 == $this->y2) { + echo '
\n"; + } + // Keep max Y updated + // One or the other will be higher... lasy mans way... + $renderer->addMaxY($this->y1); + $renderer->addMaxY($this->y2); + } } diff --git a/app/Report/ReportHtmlPageheader.php b/app/Report/ReportHtmlPageheader.php index 8451c52125..d7501bb102 100644 --- a/app/Report/ReportHtmlPageheader.php +++ b/app/Report/ReportHtmlPageheader.php @@ -18,16 +18,18 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportHtmlPageheader */ -class ReportHtmlPageheader extends ReportBasePageheader { - /** - * Render elements. - * - * @param ReportHtml $renderer - */ - public function render($renderer) { - $renderer->clearPageHeader(); - foreach ($this->elements as $element) { - $renderer->addPageHeader($element); - } - } +class ReportHtmlPageheader extends ReportBasePageheader +{ + /** + * Render elements. + * + * @param ReportHtml $renderer + */ + public function render($renderer) + { + $renderer->clearPageHeader(); + foreach ($this->elements as $element) { + $renderer->addPageHeader($element); + } + } } diff --git a/app/Report/ReportHtmlText.php b/app/Report/ReportHtmlText.php index f054953a9e..89dc8d5c27 100644 --- a/app/Report/ReportHtmlText.php +++ b/app/Report/ReportHtmlText.php @@ -18,159 +18,177 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportHtmlText */ -class ReportHtmlText extends ReportBaseText { - /** - * Render the elements. - * - * @param ReportHtml $renderer - * @param int $curx - * @param bool $attrib Is is called from a different element? - */ - public function render($renderer, $curx = 0, $attrib = true) { +class ReportHtmlText extends ReportBaseText +{ + /** + * Render the elements. + * + * @param ReportHtml $renderer + * @param int $curx + * @param bool $attrib Is is called from a different element? + */ + public function render($renderer, $curx = 0, $attrib = true) + { - // Setup the style name - if ($renderer->getCurrentStyle() != $this->styleName) { - $renderer->setCurrentStyle($this->styleName); - } - $temptext = str_replace('#PAGENUM#', $renderer->pageNo(), $this->text); - // underline «title» part of Source item - $temptext = str_replace(['«', '»'], ['', ''], $temptext); + // Setup the style name + if ($renderer->getCurrentStyle() != $this->styleName) { + $renderer->setCurrentStyle($this->styleName); + } + $temptext = str_replace('#PAGENUM#', $renderer->pageNo(), $this->text); + // underline «title» part of Source item + $temptext = str_replace([ + '«', + '»', + ], [ + '', + '', + ], $temptext); - // If any text at all - if (!empty($temptext)) { - // If called by an other element - if (!$attrib) { - $renderer->write($temptext, $this->color); - } else { - // Save the start positions - $startX = $renderer->getX(); - $startY = $renderer->getY(); - $width = $renderer->getRemainingWidth(); - // If text is wider then page width then wrap it - if ($renderer->getStringWidth($temptext) > $width) { - $lines = explode("\n", $temptext); - foreach ($lines as $line) { - echo '
'; - $line = $renderer->textWrap($line, $width); - $startY += $renderer->getTextCellHeight($line); - $renderer->setY($startY); - $renderer->write($line, $this->color); - echo "
\n"; - } - } else { - echo '
'; - $renderer->write($temptext, $this->color); - echo "
\n"; - $renderer->setX($startX + $renderer->getStringWidth($temptext)); - if ($renderer->countLines($temptext) != 1) { - $renderer->setXy(0, ($startY + $renderer->getTextCellHeight($temptext))); - } - } - } - } - } + // If any text at all + if (!empty($temptext)) { + // If called by an other element + if (!$attrib) { + $renderer->write($temptext, $this->color); + } else { + // Save the start positions + $startX = $renderer->getX(); + $startY = $renderer->getY(); + $width = $renderer->getRemainingWidth(); + // If text is wider then page width then wrap it + if ($renderer->getStringWidth($temptext) > $width) { + $lines = explode("\n", $temptext); + foreach ($lines as $line) { + echo '
'; + $line = $renderer->textWrap($line, $width); + $startY += $renderer->getTextCellHeight($line); + $renderer->setY($startY); + $renderer->write($line, $this->color); + echo "
\n"; + } + } else { + echo '
'; + $renderer->write($temptext, $this->color); + echo "
\n"; + $renderer->setX($startX + $renderer->getStringWidth($temptext)); + if ($renderer->countLines($temptext) != 1) { + $renderer->setXy(0, ($startY + $renderer->getTextCellHeight($temptext))); + } + } + } + } + } - /** - * Returns the height in points of the text element - * The height is already calculated in getWidth() - * - * @param ReportHtml $html - * - * @return float - */ - public function getHeight($html) { - $ct = substr_count($this->text, "\n"); - if ($ct > 0) { - $ct += 1; - } - $style = $html->getStyle($this->styleName); + /** + * Returns the height in points of the text element + * The height is already calculated in getWidth() + * + * @param ReportHtml $html + * + * @return float + */ + public function getHeight($html) + { + $ct = substr_count($this->text, "\n"); + if ($ct > 0) { + $ct += 1; + } + $style = $html->getStyle($this->styleName); - return ($style['size'] * $ct) * $html->cellHeightRatio; - } + return ($style['size'] * $ct) * $html->cellHeightRatio; + } - /** - * Get the width of text and wrap it too - * - * @param ReportHtml $html - * - * @return array - */ - public function getWidth($html) { - // Setup the style name - if ($html->getCurrentStyle() != $this->styleName) { - $html->setCurrentStyle($this->styleName); - } + /** + * Get the width of text and wrap it too + * + * @param ReportHtml $html + * + * @return array + */ + public function getWidth($html) + { + // Setup the style name + if ($html->getCurrentStyle() != $this->styleName) { + $html->setCurrentStyle($this->styleName); + } - // Check for the largest font size in the box - $fsize = $html->getCurrentStyleHeight(); - if ($fsize > $html->largestFontHeight) { - $html->largestFontHeight = $fsize; - } + // Check for the largest font size in the box + $fsize = $html->getCurrentStyleHeight(); + if ($fsize > $html->largestFontHeight) { + $html->largestFontHeight = $fsize; + } - // Get the line width for the text in points - $lw = $html->getStringWidth($this->text); - // Line Feed counter - Number of lines in the text - $lfct = $html->countLines($this->text); - // If there is still remaining wrap width... - if ($this->wrapWidthRemaining > 0) { - // Check with line counter too! - if ($lw >= $this->wrapWidthRemaining || $lfct > 1) { - $newtext = ''; - $wrapWidthRemaining = $this->wrapWidthRemaining; - $lines = explode("\n", $this->text); - // Go throught the text line by line - foreach ($lines as $line) { - // Line width in points + a little margin - $lw = $html->getStringWidth($line); - // If the line has to be wraped - if ($lw > $wrapWidthRemaining) { - $words = explode(' ', $line); - $addspace = count($words); - $lw = 0; - foreach ($words as $word) { - $addspace--; - $lw += $html->getStringWidth($word . ' '); - if ($lw <= $wrapWidthRemaining) { - $newtext .= $word; - if ($addspace != 0) { - $newtext .= ' '; - } - } else { - $lw = $html->getStringWidth($word . ' '); - $newtext .= "\n$word"; - if ($addspace != 0) { - $newtext .= ' '; - } - // Reset the wrap width to the cell width - $wrapWidthRemaining = $this->wrapWidthCell; - } - } - } else { - $newtext .= $line; - } - // Check the Line Feed counter - if ($lfct > 1) { - // Add a new line feed as long as it’s not the last line - $newtext .= "\n"; - // Reset the line width - $lw = 0; - // Reset the wrap width to the cell width - $wrapWidthRemaining = $this->wrapWidthCell; - } - $lfct--; - } - $this->text = $newtext; - $lfct = substr_count($this->text, "\n"); + // Get the line width for the text in points + $lw = $html->getStringWidth($this->text); + // Line Feed counter - Number of lines in the text + $lfct = $html->countLines($this->text); + // If there is still remaining wrap width... + if ($this->wrapWidthRemaining > 0) { + // Check with line counter too! + if ($lw >= $this->wrapWidthRemaining || $lfct > 1) { + $newtext = ''; + $wrapWidthRemaining = $this->wrapWidthRemaining; + $lines = explode("\n", $this->text); + // Go throught the text line by line + foreach ($lines as $line) { + // Line width in points + a little margin + $lw = $html->getStringWidth($line); + // If the line has to be wraped + if ($lw > $wrapWidthRemaining) { + $words = explode(' ', $line); + $addspace = count($words); + $lw = 0; + foreach ($words as $word) { + $addspace--; + $lw += $html->getStringWidth($word . ' '); + if ($lw <= $wrapWidthRemaining) { + $newtext .= $word; + if ($addspace != 0) { + $newtext .= ' '; + } + } else { + $lw = $html->getStringWidth($word . ' '); + $newtext .= "\n$word"; + if ($addspace != 0) { + $newtext .= ' '; + } + // Reset the wrap width to the cell width + $wrapWidthRemaining = $this->wrapWidthCell; + } + } + } else { + $newtext .= $line; + } + // Check the Line Feed counter + if ($lfct > 1) { + // Add a new line feed as long as it’s not the last line + $newtext .= "\n"; + // Reset the line width + $lw = 0; + // Reset the wrap width to the cell width + $wrapWidthRemaining = $this->wrapWidthCell; + } + $lfct--; + } + $this->text = $newtext; + $lfct = substr_count($this->text, "\n"); - return [$lw, 1, $lfct]; - } - } - $l = 0; - $lfct = substr_count($this->text, "\n"); - if ($lfct > 0) { - $l = 2; - } + return [ + $lw, + 1, + $lfct, + ]; + } + } + $l = 0; + $lfct = substr_count($this->text, "\n"); + if ($lfct > 0) { + $l = 2; + } - return [$lw, $l, $lfct]; - } + return [ + $lw, + $l, + $lfct, + ]; + } } diff --git a/app/Report/ReportHtmlTextbox.php b/app/Report/ReportHtmlTextbox.php index a70c29d384..1cf212e48b 100644 --- a/app/Report/ReportHtmlTextbox.php +++ b/app/Report/ReportHtmlTextbox.php @@ -18,254 +18,256 @@ namespace Fisharebest\Webtrees\Report; /** * Class ReportHtmlTextbox */ -class ReportHtmlTextbox extends ReportBaseTextbox { - /** - * Render the elements. - * - * @param ReportHtml $renderer - */ - public function render($renderer) { - // checkFootnote - $newelements = []; - $lastelement = []; - $footnote_element = []; - // Element counter - $cE = count($this->elements); - //-- collapse duplicate elements - for ($i = 0; $i < $cE; $i++) { - $element = $this->elements[$i]; - if (is_object($element)) { - if ($element instanceof ReportBaseText) { - if (!empty($footnote_element)) { - ksort($footnote_element); - foreach ($footnote_element as $links) { - $newelements[] = $links; - } - $footnote_element = []; - } - if (empty($lastelement)) { - $lastelement = $element; - } else { - // Checking if the Text has the same style - if ($element->getStyleName() == $lastelement->getStyleName()) { - $lastelement->addText(str_replace("\n", '
', $element->getValue())); - } elseif (!empty($lastelement)) { - $newelements[] = $lastelement; - $lastelement = $element; - } - } - } // Collect the Footnote links - elseif ($element instanceof ReportBaseFootnote) { - // Check if the Footnote has been set with it’s link number - $renderer->checkFootnote($element); - // Save first the last element if any - if (!empty($lastelement)) { - $newelements[] = $lastelement; - $lastelement = []; - } - // Save the Footnote with it’s link number as key for sorting later - $footnote_element[$element->num] = $element; - } //-- do not keep empty footnotes - elseif (!($element instanceof ReportBaseFootnote) || trim($element->getValue()) != '') { - if (!empty($footnote_element)) { - ksort($footnote_element); - foreach ($footnote_element as $links) { - $newelements[] = $links; - } - $footnote_element = []; - } - if (!empty($lastelement)) { - $newelements[] = $lastelement; - $lastelement = []; - } - $newelements[] = $element; - } - } else { - if (!empty($lastelement)) { - $newelements[] = $lastelement; - $lastelement = []; - } - if (!empty($footnote_element)) { - ksort($footnote_element); - foreach ($footnote_element as $links) { - $newelements[] = $links; - } - $footnote_element = []; - } - $newelements[] = $element; - } - } - if (!empty($lastelement)) { - $newelements[] = $lastelement; - } - if (!empty($footnote_element)) { - ksort($footnote_element); - foreach ($footnote_element as $links) { - $newelements[] = $links; - } - } - $this->elements = $newelements; - unset($footnote_element, $lastelement, $links, $newelements); +class ReportHtmlTextbox extends ReportBaseTextbox +{ + /** + * Render the elements. + * + * @param ReportHtml $renderer + */ + public function render($renderer) + { + // checkFootnote + $newelements = []; + $lastelement = []; + $footnote_element = []; + // Element counter + $cE = count($this->elements); + //-- collapse duplicate elements + for ($i = 0; $i < $cE; $i++) { + $element = $this->elements[$i]; + if (is_object($element)) { + if ($element instanceof ReportBaseText) { + if (!empty($footnote_element)) { + ksort($footnote_element); + foreach ($footnote_element as $links) { + $newelements[] = $links; + } + $footnote_element = []; + } + if (empty($lastelement)) { + $lastelement = $element; + } else { + // Checking if the Text has the same style + if ($element->getStyleName() == $lastelement->getStyleName()) { + $lastelement->addText(str_replace("\n", '
', $element->getValue())); + } elseif (!empty($lastelement)) { + $newelements[] = $lastelement; + $lastelement = $element; + } + } + } // Collect the Footnote links + elseif ($element instanceof ReportBaseFootnote) { + // Check if the Footnote has been set with it’s link number + $renderer->checkFootnote($element); + // Save first the last element if any + if (!empty($lastelement)) { + $newelements[] = $lastelement; + $lastelement = []; + } + // Save the Footnote with it’s link number as key for sorting later + $footnote_element[$element->num] = $element; + } //-- do not keep empty footnotes + elseif (!($element instanceof ReportBaseFootnote) || trim($element->getValue()) != '') { + if (!empty($footnote_element)) { + ksort($footnote_element); + foreach ($footnote_element as $links) { + $newelements[] = $links; + } + $footnote_element = []; + } + if (!empty($lastelement)) { + $newelements[] = $lastelement; + $lastelement = []; + } + $newelements[] = $element; + } + } else { + if (!empty($lastelement)) { + $newelements[] = $lastelement; + $lastelement = []; + } + if (!empty($footnote_element)) { + ksort($footnote_element); + foreach ($footnote_element as $links) { + $newelements[] = $links; + } + $footnote_element = []; + } + $newelements[] = $element; + } + } + if (!empty($lastelement)) { + $newelements[] = $lastelement; + } + if (!empty($footnote_element)) { + ksort($footnote_element); + foreach ($footnote_element as $links) { + $newelements[] = $links; + } + } + $this->elements = $newelements; + unset($footnote_element, $lastelement, $links, $newelements); - $cP = 0; // Class Padding + $cP = 0; // Class Padding - // Used with line breaks and cell height calculation within this box only - $renderer->largestFontHeight = 0; + // Used with line breaks and cell height calculation within this box only + $renderer->largestFontHeight = 0; - // Current position - if ($this->left == '.') { - $cX = $renderer->getX(); - } else { - $cX = $this->left; - $renderer->setX($cX); - } - // Current position (top) - if ($this->top == '.') { - $this->top = $renderer->getY(); - } else { - $renderer->setY($this->top); - } + // Current position + if ($this->left == '.') { + $cX = $renderer->getX(); + } else { + $cX = $this->left; + $renderer->setX($cX); + } + // Current position (top) + if ($this->top == '.') { + $this->top = $renderer->getY(); + } else { + $renderer->setY($this->top); + } - // Check the width if set to page wide OR set by xml to larger then page wide - if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) { - $this->width = $renderer->getRemainingWidth(); - } - // Setup the CellPadding - if ($this->padding) { - $cP = $renderer->cPadding; - } + // Check the width if set to page wide OR set by xml to larger then page wide + if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) { + $this->width = $renderer->getRemainingWidth(); + } + // Setup the CellPadding + if ($this->padding) { + $cP = $renderer->cPadding; + } - // For padding, we have to use less wrap width - $cW = $this->width - ($cP * 2); + // For padding, we have to use less wrap width + $cW = $this->width - ($cP * 2); - //-- calculate the text box height - // Number of lines, will be converted to height - $cHT = 0; - // Element height (exept text) - $eH = 0; - // Footnote height (in points) - $fH = 0; - $w = 0; - //-- $lw is an array - // 0 => last line width - // 1 => 1 if text was wrapped, 0 if text did not wrap - // 2 => number of LF - $lw = []; - // Element counter - $cE = count($this->elements); - for ($i = 0; $i < $cE; $i++) { - if (is_object($this->elements[$i])) { - $ew = $this->elements[$i]->setWrapWidth($cW - $w - 2, $cW); - if ($ew == $cW) { - $w = 0; - } - $lw = $this->elements[$i]->getWidth($renderer); - // Text is already gets the # LF - $cHT += $lw[2]; - if ($lw[1] == 1) { - $w = $lw[0]; - } elseif ($lw[1] == 2) { - $w = 0; - } else { - $w += $lw[0]; - } - if ($w > $cW) { - $w = $lw[0]; - } - // For anything else but text (images), get the height - $eH += $this->elements[$i]->getHeight($renderer); - } else { - $fH += abs($renderer->getFootnotesHeight($cW)); - } - } - // Add up what’s the final height - $cH = $this->height; - // If any element exist - if ($cE > 0) { - // Check if this is text or some other element, like images - if ($eH == 0) { - // Number of LF but at least one line - $cHT = ($cHT + 1) * $renderer->cellHeightRatio; - // Calculate the cell hight with the largest font size used - $cHT = $cHT * $renderer->largestFontHeight; - if ($cH < $cHT) { - $cH = $cHT; - } - } // This is any other element - else { - if ($cH < $eH) { - $cH = $eH; - } - // Add Footnote height to the rest of the height - $cH += $fH; - } - } + //-- calculate the text box height + // Number of lines, will be converted to height + $cHT = 0; + // Element height (exept text) + $eH = 0; + // Footnote height (in points) + $fH = 0; + $w = 0; + //-- $lw is an array + // 0 => last line width + // 1 => 1 if text was wrapped, 0 if text did not wrap + // 2 => number of LF + $lw = []; + // Element counter + $cE = count($this->elements); + for ($i = 0; $i < $cE; $i++) { + if (is_object($this->elements[$i])) { + $ew = $this->elements[$i]->setWrapWidth($cW - $w - 2, $cW); + if ($ew == $cW) { + $w = 0; + } + $lw = $this->elements[$i]->getWidth($renderer); + // Text is already gets the # LF + $cHT += $lw[2]; + if ($lw[1] == 1) { + $w = $lw[0]; + } elseif ($lw[1] == 2) { + $w = 0; + } else { + $w += $lw[0]; + } + if ($w > $cW) { + $w = $lw[0]; + } + // For anything else but text (images), get the height + $eH += $this->elements[$i]->getHeight($renderer); + } else { + $fH += abs($renderer->getFootnotesHeight($cW)); + } + } + // Add up what’s the final height + $cH = $this->height; + // If any element exist + if ($cE > 0) { + // Check if this is text or some other element, like images + if ($eH == 0) { + // Number of LF but at least one line + $cHT = ($cHT + 1) * $renderer->cellHeightRatio; + // Calculate the cell hight with the largest font size used + $cHT = $cHT * $renderer->largestFontHeight; + if ($cH < $cHT) { + $cH = $cHT; + } + } // This is any other element + else { + if ($cH < $eH) { + $cH = $eH; + } + // Add Footnote height to the rest of the height + $cH += $fH; + } + } - unset($lw, $cHT, $fH, $w); + unset($lw, $cHT, $fH, $w); - // Finaly, check the last cells height - if ($cH < $renderer->lastCellHeight) { - $cH = $renderer->lastCellHeight; - } - // Update max Y incase of a pagebreak - // We don't want to over write any images or other stuff - $renderer->addMaxY($this->top + $cH); + // Finaly, check the last cells height + if ($cH < $renderer->lastCellHeight) { + $cH = $renderer->lastCellHeight; + } + // Update max Y incase of a pagebreak + // We don't want to over write any images or other stuff + $renderer->addMaxY($this->top + $cH); - // Start to print HTML - echo '
'; + // Start to print HTML + echo '
'; - // Do a little "margin" trick before print - // to get the correct current position => "." - $cXT = $renderer->getX(); - $cYT = $renderer->getY(); - $renderer->setXy(0, 0); + // Do a little "margin" trick before print + // to get the correct current position => "." + $cXT = $renderer->getX(); + $cYT = $renderer->getY(); + $renderer->setXy(0, 0); - // Print the text elements - foreach ($this->elements as $element) { - if (is_object($element)) { - $element->render($renderer, $cX, false); - } elseif (is_string($element) && $element == 'footnotetexts') { - $renderer->footnotes(); - } elseif (is_string($element) && $element == 'addpage') { - $renderer->addPage(); - } - } - echo "
\n"; + // Print the text elements + foreach ($this->elements as $element) { + if (is_object($element)) { + $element->render($renderer, $cX, false); + } elseif (is_string($element) && $element == 'footnotetexts') { + $renderer->footnotes(); + } elseif (is_string($element) && $element == 'addpage') { + $renderer->addPage(); + } + } + echo "
\n"; - // Reset "margins" - $renderer->setXy($cXT, $cYT); - // This will be mostly used to trick the multiple images last height - if ($this->reseth) { - $cH = 0; - } - // New line and some clean up - if (!$this->newline) { - $renderer->setXy($cX + $this->width, $this->top); - $renderer->lastCellHeight = $cH; - } else { - $renderer->setXy(0, $this->top + $cH + ($cP * 2)); - $renderer->lastCellHeight = 0; - } - } + // Reset "margins" + $renderer->setXy($cXT, $cYT); + // This will be mostly used to trick the multiple images last height + if ($this->reseth) { + $cH = 0; + } + // New line and some clean up + if (!$this->newline) { + $renderer->setXy($cX + $this->width, $this->top); + $renderer->lastCellHeight = $cH; + } else { + $renderer->setXy(0, $this->top + $cH + ($cP * 2)); + $renderer->lastCellHeight = 0; + } + } } diff --git a/app/Report/ReportParserBase.php b/app/Report/ReportParserBase.php index 324dead3df..26cb7dbac1 100644 --- a/app/Report/ReportParserBase.php +++ b/app/Report/ReportParserBase.php @@ -20,75 +20,89 @@ use Fisharebest\Webtrees\Tree; /** * Class ReportParserBase */ -class ReportParserBase { - /** @var resource The XML parser */ - protected $xml_parser; +class ReportParserBase +{ + /** @var resource The XML parser */ + protected $xml_parser; - /** @var string Text contents of tags */ - protected $text = ''; + /** @var string Text contents of tags */ + protected $text = ''; - /** - * Create a parser for a report - * - * @param string $report The XML filename - * @param ReportBase $report_root - * @param string[][] $vars - * @param Tree $tree - */ - public function __construct($report, ReportBase $report_root, $vars, Tree $tree) { - $this->xml_parser = xml_parser_create(); - xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false); - xml_set_element_handler($this->xml_parser, [$this, 'startElement'], [$this, 'endElement']); - xml_set_character_data_handler($this->xml_parser, [$this, 'characterData']); + /** + * Create a parser for a report + * + * @param string $report The XML filename + * @param ReportBase $report_root + * @param string[][] $vars + * @param Tree $tree + */ + public function __construct($report, ReportBase $report_root, $vars, Tree $tree) + { + $this->xml_parser = xml_parser_create(); + xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false); + xml_set_element_handler($this->xml_parser, [ + $this, + 'startElement', + ], [ + $this, + 'endElement', + ]); + xml_set_character_data_handler($this->xml_parser, [ + $this, + 'characterData', + ]); - $fp = fopen($report, 'r'); - while (($data = fread($fp, 4096))) { - if (!xml_parse($this->xml_parser, $data, feof($fp))) { - throw new \DomainException(sprintf( - 'XML error: %s at line %d', - xml_error_string(xml_get_error_code($this->xml_parser)), - xml_get_current_line_number($this->xml_parser) - )); - } - } + $fp = fopen($report, 'r'); + while (($data = fread($fp, 4096))) { + if (!xml_parse($this->xml_parser, $data, feof($fp))) { + throw new \DomainException(sprintf( + 'XML error: %s at line %d', + xml_error_string(xml_get_error_code($this->xml_parser)), + xml_get_current_line_number($this->xml_parser) + )); + } + } - xml_parser_free($this->xml_parser); - } + xml_parser_free($this->xml_parser); + } - /** - * XML handler for an opening (or self-closing) tag. - * - * @param resource $parser The resource handler for the xml parser - * @param string $name The name of the xml element parsed - * @param string[] $attrs An array of key value pairs for the attributes - */ - protected function startElement($parser, $name, $attrs) { - $method = $name . 'StartHandler'; - if (method_exists($this, $method)) { - $this->$method($attrs); - } - } + /** + * XML handler for an opening (or self-closing) tag. + * + * @param resource $parser The resource handler for the xml parser + * @param string $name The name of the xml element parsed + * @param string[] $attrs An array of key value pairs for the attributes + */ + protected function startElement($parser, $name, $attrs) + { + $method = $name . 'StartHandler'; + if (method_exists($this, $method)) { + $this->$method($attrs); + } + } - /** - * XML handler for a closing tag. - * - * @param resource $parser the resource handler for the xml parser - * @param string $name the name of the xml element parsed - */ - protected function endElement($parser, $name) { - $method = $name . 'EndHandler'; - if (method_exists($this, $method)) { - $this->$method(); - } - } + /** + * XML handler for a closing tag. + * + * @param resource $parser the resource handler for the xml parser + * @param string $name the name of the xml element parsed + */ + protected function endElement($parser, $name) + { + $method = $name . 'EndHandler'; + if (method_exists($this, $method)) { + $this->$method(); + } + } - /** - * XML handler for character data. - * - * @param resource $parser The resource handler for the xml parser - * @param string $data The name of the xml element parsed - */ - protected function characterData($parser, $data) { - $this->text .= $data; - } + /** + * XML handler for character data. + * + * @param resource $parser The resource handler for the xml parser + * @param string $data The name of the xml element parsed + */ + protected function characterData($parser, $data) + { + $this->text .= $data; + } } diff --git a/app/Report/ReportParserGenerate.php b/app/Report/ReportParserGenerate.php index ba74ed910e..2267f52af8 100644 --- a/app/Report/ReportParserGenerate.php +++ b/app/Report/ReportParserGenerate.php @@ -35,2730 +35,2885 @@ use Fisharebest\Webtrees\Tree; /** * Class ReportParserGenerate - parse a report.xml file and generate the report. */ -class ReportParserGenerate extends ReportParserBase { - /** @var bool Are we collecting data from elements */ - private $process_footnote = true; +class ReportParserGenerate extends ReportParserBase +{ + /** @var bool Are we collecting data from elements */ + private $process_footnote = true; - /** @var bool Are we currently outputing data? */ - private $print_data = false; + /** @var bool Are we currently outputing data? */ + private $print_data = false; - /** @var bool[] Push-down stack of $print_data */ - private $print_data_stack = []; + /** @var bool[] Push-down stack of $print_data */ + private $print_data_stack = []; - /** @var int Are we processing GEDCOM data */ - private $process_gedcoms = 0; + /** @var int Are we processing GEDCOM data */ + private $process_gedcoms = 0; - /** @var int Are we processing conditionals */ - private $process_ifs = 0; + /** @var int Are we processing conditionals */ + private $process_ifs = 0; - /** @var int Are we processing repeats*/ - private $process_repeats = 0; + /** @var int Are we processing repeats */ + private $process_repeats = 0; - /** @var int Quantity of data to repeat during loops */ - private $repeat_bytes = 0; + /** @var int Quantity of data to repeat during loops */ + private $repeat_bytes = 0; - /** @var array[] Repeated data when iterating over loops */ - private $repeats = []; + /** @var array[] Repeated data when iterating over loops */ + private $repeats = []; - /** @var array[] Nested repeating data */ - private $repeats_stack = []; - - /** @var ReportBase[] Nested repeating data */ - private $wt_report_stack = []; - - /** @var resource Nested repeating data */ - private $parser; - - /** @var resource[] Nested repeating data */ - private $parser_stack = []; - - /** @var string The current GEDCOM record */ - private $gedrec = ''; - - /** @var string[] Nested GEDCOM records */ - private $gedrec_stack = []; - - /** @var ReportBaseElement The currently processed element */ - private $current_element; - - /** @var ReportBaseElement The currently processed element */ - private $footnote_element; - - /** @var string The GEDCOM fact currently being processed */ - private $fact = ''; - - /** @var string The GEDCOM value currently being processed */ - private $desc = ''; - - /** @var string The GEDCOM type currently being processed */ - private $type = ''; - - /** @var int The current generational level */ - private $generation = 1; - - /** @var array Source data for processing lists */ - private $list = []; - - /** @var int Number of items in lists */ - private $list_total = 0; - - /** @var int Number of items filtered from lists */ - private $list_private = 0; - - /** @var string The filename of the XML report */ - protected $report; - - /** @var ReportBase A factory for creating report elements */ - private $report_root; - - /** @var ReportBase Nested report elements */ - private $wt_report; - - /** @var string[][] Variables defined in the report at run-time */ - private $vars; - - /** @var Tree The current tree */ - private $tree; - - /** - * Create a parser for a report - * - * @param string $report The XML filename - * @param ReportBase $report_root - * @param string[][] $vars - * @param Tree $tree - */ - public function __construct($report, ReportBase $report_root, array $vars, Tree $tree) { - $this->report = $report; - $this->report_root = $report_root; - $this->wt_report = $report_root; - $this->current_element = new ReportBaseElement; - $this->vars = $vars; - $this->tree = $tree; - - parent::__construct($report, $report_root, $vars, $tree); - } - - /** - * XML start element handler - * - * This function is called whenever a starting element is reached - * The element handler will be called if found, otherwise it must be HTML - * - * @param resource $parser the resource handler for the XML parser - * @param string $name the name of the XML element parsed - * @param array $attrs an array of key value pairs for the attributes - */ - protected function startElement($parser, $name, $attrs) { - $newattrs = []; - - foreach ($attrs as $key => $value) { - if (preg_match("/^\\$(\w+)$/", $value, $match)) { - if ((isset($this->vars[$match[1]]['id'])) && (!isset($this->vars[$match[1]]['gedcom']))) { - $value = $this->vars[$match[1]]['id']; - } - } - $newattrs[$key] = $value; - } - $attrs = $newattrs; - if ($this->process_footnote && ($this->process_ifs === 0 || $name === 'if') && ($this->process_gedcoms === 0 || $name === 'Gedcom') && ($this->process_repeats === 0 || $name === 'Facts' || $name === 'RepeatTag')) { - $start_method = $name . 'StartHandler'; - $end_method = $name . 'EndHandler'; - if (method_exists($this, $start_method)) { - $this->$start_method($attrs); - } elseif (!method_exists($this, $end_method)) { - $this->htmlStartHandler($name, $attrs); - } - } - } - - /** - * XML end element handler - * - * This function is called whenever an ending element is reached - * The element handler will be called if found, otherwise it must be HTML - * - * @param resource $parser the resource handler for the XML parser - * @param string $name the name of the XML element parsed - */ - protected function endElement($parser, $name) { - if (($this->process_footnote || $name === 'Footnote') && ($this->process_ifs === 0 || $name === 'if') && ($this->process_gedcoms === 0 || $name === 'Gedcom') && ($this->process_repeats === 0 || $name === 'Facts' || $name === 'RepeatTag' || $name === 'List' || $name === 'Relatives')) { - $start_method = $name . 'StartHandler'; - $end_method = $name . 'EndHandler'; - if (method_exists($this, $end_method)) { - $this->$end_method(); - } elseif (!method_exists($this, $start_method)) { - $this->htmlEndHandler($name); - } - } - } - - /** - * XML character data handler - * - * @param resource $parser the resource handler for the XML parser - * @param string $data the name of the XML element parsed - */ - protected function characterData($parser, $data) { - if ($this->print_data && $this->process_gedcoms === 0 && $this->process_ifs === 0 && $this->process_repeats === 0) { - $this->current_element->addText($data); - } - } - - /** - * XML