1*a25f0a04SGreg Roach<?php 2*a25f0a04SGreg Roachnamespace Webtrees; 3*a25f0a04SGreg Roach 4*a25f0a04SGreg Roach/** 5*a25f0a04SGreg Roach * webtrees: online genealogy 6*a25f0a04SGreg Roach * Copyright (C) 2015 webtrees development team 7*a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 8*a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 9*a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 10*a25f0a04SGreg Roach * (at your option) any later version. 11*a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 12*a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*a25f0a04SGreg Roach * GNU General Public License for more details. 15*a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 16*a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 17*a25f0a04SGreg Roach */ 18*a25f0a04SGreg Roach 19*a25f0a04SGreg Roach/** 20*a25f0a04SGreg Roach * class ReportHtmlFootnote 21*a25f0a04SGreg Roach */ 22*a25f0a04SGreg Roachclass ReportHtmlFootnote extends ReportBaseFootnote { 23*a25f0a04SGreg Roach /** 24*a25f0a04SGreg Roach * HTML Footnotes number renderer 25*a25f0a04SGreg Roach * 26*a25f0a04SGreg Roach * @param ReportHtml $renderer 27*a25f0a04SGreg Roach * 28*a25f0a04SGreg Roach * @return void 29*a25f0a04SGreg Roach */ 30*a25f0a04SGreg Roach function render($renderer) { 31*a25f0a04SGreg Roach $renderer->setCurrentStyle("footnotenum"); 32*a25f0a04SGreg Roach echo "<a href=\"#footnote", $this->num, "\"><sup>"; 33*a25f0a04SGreg Roach $renderer->write($renderer->entityRTL . $this->num); 34*a25f0a04SGreg Roach echo "</sup></a>\n"; 35*a25f0a04SGreg Roach } 36*a25f0a04SGreg Roach 37*a25f0a04SGreg Roach /** 38*a25f0a04SGreg Roach * Write the Footnote text 39*a25f0a04SGreg Roach 40*a25f0a04SGreg Roach * Uses style name "footnote" by default 41*a25f0a04SGreg Roach 42*a25f0a04SGreg Roach 43*a25f0a04SGreg Roach 44*a25f0a04SGreg Roach* 45*a25f0a04SGreg Roach*@param ReportHtml $html 46*a25f0a04SGreg Roach 47*a25f0a04SGreg Roach 48*a25f0a04SGreg Roach 49*a25f0a04SGreg Roach* 50*a25f0a04SGreg Roach*@return void 51*a25f0a04SGreg Roach */ 52*a25f0a04SGreg Roach function renderFootnote($html) { 53*a25f0a04SGreg Roach 54*a25f0a04SGreg Roach if ($html->getCurrentStyle() != $this->styleName) { 55*a25f0a04SGreg Roach $html->setCurrentStyle($this->styleName); 56*a25f0a04SGreg Roach } 57*a25f0a04SGreg Roach 58*a25f0a04SGreg Roach $temptext = str_replace("#PAGENUM#", $html->pageNo(), $this->text); 59*a25f0a04SGreg Roach // underline «title» part of Source item 60*a25f0a04SGreg Roach $temptext = str_replace(array('«', '»'), array('<u>', '</u>'), $temptext); 61*a25f0a04SGreg Roach echo "\n<div><a name=\"footnote", $this->num, "\"></a>"; 62*a25f0a04SGreg Roach $html->write($this->num . ". " . $temptext); 63*a25f0a04SGreg Roach echo "</div>"; 64*a25f0a04SGreg Roach 65*a25f0a04SGreg Roach $html->setXy(0, $html->getY() + $this->getFootnoteHeight($html)); 66*a25f0a04SGreg Roach } 67*a25f0a04SGreg Roach 68*a25f0a04SGreg Roach /** 69*a25f0a04SGreg Roach * Calculates the Footnotes height 70*a25f0a04SGreg Roach 71*a25f0a04SGreg Roach 72*a25f0a04SGreg Roach 73*a25f0a04SGreg Roach* 74*a25f0a04SGreg Roach*@param ReportHtml $html 75*a25f0a04SGreg Roach * @param integer $cellWidth The width of the cell to use it for text wraping 76*a25f0a04SGreg Roach 77*a25f0a04SGreg Roach 78*a25f0a04SGreg Roach 79*a25f0a04SGreg Roach* 80*a25f0a04SGreg Roach*@return integer Footnote height in points 81*a25f0a04SGreg Roach */ 82*a25f0a04SGreg Roach function getFootnoteHeight($html, $cellWidth = 0) { 83*a25f0a04SGreg Roach if ($html->getCurrentStyle() != $this->styleName) { 84*a25f0a04SGreg Roach $html->setCurrentStyle($this->styleName); 85*a25f0a04SGreg Roach } 86*a25f0a04SGreg Roach 87*a25f0a04SGreg Roach if ($cellWidth > 0) { 88*a25f0a04SGreg Roach $this->text = $html->textWrap($this->text, $cellWidth); 89*a25f0a04SGreg Roach } 90*a25f0a04SGreg Roach $this->text = $this->text . "\n\n"; 91*a25f0a04SGreg Roach $ct = substr_count($this->text, "\n"); 92*a25f0a04SGreg Roach $fsize = $html->getCurrentStyleHeight(); 93*a25f0a04SGreg Roach return ($fsize * $ct) * $html->cellHeightRatio; 94*a25f0a04SGreg Roach } 95*a25f0a04SGreg Roach 96*a25f0a04SGreg Roach /** 97*a25f0a04SGreg Roach * Get the width of text 98*a25f0a04SGreg Roach 99*a25f0a04SGreg Roach * Breaks up a text into lines if needed 100*a25f0a04SGreg Roach 101*a25f0a04SGreg Roach 102*a25f0a04SGreg Roach 103*a25f0a04SGreg Roach* 104*a25f0a04SGreg Roach*@param ReportHtml $html 105*a25f0a04SGreg Roach 106*a25f0a04SGreg Roach 107*a25f0a04SGreg Roach 108*a25f0a04SGreg Roach* 109*a25f0a04SGreg Roach*@return array 110*a25f0a04SGreg Roach */ 111*a25f0a04SGreg Roach function getWidth($html) { 112*a25f0a04SGreg Roach // Setup the style name 113*a25f0a04SGreg Roach $html->setCurrentStyle("footnotenum"); 114*a25f0a04SGreg Roach 115*a25f0a04SGreg Roach // Check for the largest font size in the box 116*a25f0a04SGreg Roach $fsize = $html->getCurrentStyleHeight(); 117*a25f0a04SGreg Roach if ($fsize > $html->largestFontHeight) { 118*a25f0a04SGreg Roach $html->largestFontHeight = $fsize; 119*a25f0a04SGreg Roach } 120*a25f0a04SGreg Roach 121*a25f0a04SGreg Roach // Returns the Object if already numbered else false 122*a25f0a04SGreg Roach if (empty($this->num)) { 123*a25f0a04SGreg Roach $html->checkFootnote($this); 124*a25f0a04SGreg Roach } 125*a25f0a04SGreg Roach 126*a25f0a04SGreg Roach // Get the line width for the text in points + a little margin 127*a25f0a04SGreg Roach $lw = $html->GetStringWidth($this->numText); 128*a25f0a04SGreg Roach // Line Feed counter - Number of lines in the text 129*a25f0a04SGreg Roach $lfct = $html->countLines($this->numText); 130*a25f0a04SGreg Roach // If there is still remaining wrap width... 131*a25f0a04SGreg Roach if ($this->wrapWidthRemaining > 0) { 132*a25f0a04SGreg Roach // Check with line counter too! 133*a25f0a04SGreg Roach if (($lw >= $this->wrapWidthRemaining) or ($lfct > 1)) { 134*a25f0a04SGreg Roach $newtext = ""; 135*a25f0a04SGreg Roach $wrapWidthRemaining = $this->wrapWidthRemaining; 136*a25f0a04SGreg Roach $lines = explode("\n", $this->numText); 137*a25f0a04SGreg Roach // Go throught the text line by line 138*a25f0a04SGreg Roach foreach ($lines as $line) { 139*a25f0a04SGreg Roach // Line width in points + a little margin 140*a25f0a04SGreg Roach $lw = $html->GetStringWidth($line); 141*a25f0a04SGreg Roach // If the line has to be wraped 142*a25f0a04SGreg Roach if ($lw > $wrapWidthRemaining) { 143*a25f0a04SGreg Roach $words = explode(" ", $line); 144*a25f0a04SGreg Roach $addspace = count($words); 145*a25f0a04SGreg Roach $lw = 0; 146*a25f0a04SGreg Roach foreach ($words as $word) { 147*a25f0a04SGreg Roach $addspace--; 148*a25f0a04SGreg Roach $lw += $html->GetStringWidth($word . " "); 149*a25f0a04SGreg Roach if ($lw <= $wrapWidthRemaining) { 150*a25f0a04SGreg Roach $newtext .= $word; 151*a25f0a04SGreg Roach if ($addspace != 0) { 152*a25f0a04SGreg Roach $newtext .= " "; 153*a25f0a04SGreg Roach } 154*a25f0a04SGreg Roach } else { 155*a25f0a04SGreg Roach $lw = $html->GetStringWidth($word . " "); 156*a25f0a04SGreg Roach $newtext .= "\n$word"; 157*a25f0a04SGreg Roach if ($addspace != 0) { 158*a25f0a04SGreg Roach $newtext .= " "; 159*a25f0a04SGreg Roach } 160*a25f0a04SGreg Roach // Reset the wrap width to the cell width 161*a25f0a04SGreg Roach $wrapWidthRemaining = $this->wrapWidthCell; 162*a25f0a04SGreg Roach } 163*a25f0a04SGreg Roach } 164*a25f0a04SGreg Roach } else { 165*a25f0a04SGreg Roach $newtext .= $line; 166*a25f0a04SGreg Roach } 167*a25f0a04SGreg Roach // Check the Line Feed counter 168*a25f0a04SGreg Roach if ($lfct > 1) { 169*a25f0a04SGreg Roach // Add a new line feed as long as it’s not the last line 170*a25f0a04SGreg Roach $newtext .= "\n"; 171*a25f0a04SGreg Roach // Reset the line width 172*a25f0a04SGreg Roach $lw = 0; 173*a25f0a04SGreg Roach // Reset the wrap width to the cell width 174*a25f0a04SGreg Roach $wrapWidthRemaining = $this->wrapWidthCell; 175*a25f0a04SGreg Roach } 176*a25f0a04SGreg Roach $lfct--; 177*a25f0a04SGreg Roach } 178*a25f0a04SGreg Roach $this->numText = $newtext; 179*a25f0a04SGreg Roach $lfct = substr_count($this->numText, "\n"); 180*a25f0a04SGreg Roach return array($lw, 1, $lfct); 181*a25f0a04SGreg Roach } 182*a25f0a04SGreg Roach } 183*a25f0a04SGreg Roach $l = 0; 184*a25f0a04SGreg Roach $lfct = substr_count($this->numText, "\n"); 185*a25f0a04SGreg Roach if ($lfct > 0) { 186*a25f0a04SGreg Roach $l = 2; 187*a25f0a04SGreg Roach } 188*a25f0a04SGreg Roach return array($lw, $l, $lfct); 189*a25f0a04SGreg Roach } 190*a25f0a04SGreg Roach} 191