Skip to content

Commit ffaf8d5

Browse files
committed
Migrate number of lines calculation for pdf documents
1 parent e96e9a8 commit ffaf8d5

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

src/wcmf/lib/pdf/PDF.php

+27-28
Original file line numberDiff line numberDiff line change
@@ -172,47 +172,46 @@ public function CheckPageBreak($h) {
172172
* @param $txt The text
173173
*/
174174
public function NbLines($w, $txt) {
175-
$cw=&$this->CurrentFont['cw'];
176-
if($w==0) {
177-
$w=$this->w-$this->rMargin-$this->x;
175+
if ($w==0) {
176+
$w = $this->w-$this->rMargin-$this->x;
178177
}
179-
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
180-
$s=str_replace("\r", '', $txt);
181-
$nb=strlen($s);
182-
if($nb>0 && $s[$nb-1]=="\n") {
178+
$wmax = $w-2*$this->cMargin;
179+
$s = str_replace("\r", '', $txt);
180+
$nb = strlen($s);
181+
if ($nb>0 && $s[$nb-1]=="\n") {
183182
$nb--;
184183
}
185-
$sep=-1;
186-
$i=0;
187-
$j=0;
188-
$l=0;
189-
$nl=1;
190-
while($i<$nb) {
191-
$c=$s[$i];
192-
if($c=="\n") {
184+
$sep = -1;
185+
$i = 0;
186+
$j = 0;
187+
$l = 0;
188+
$nl = 1;
189+
while ($i<$nb) {
190+
$c = $s[$i];
191+
if ($c=="\n") {
193192
$i++;
194-
$sep=-1;
195-
$j=$i;
196-
$l=0;
193+
$sep = -1;
194+
$j = $i;
195+
$l = 0;
197196
$nl++;
198197
continue;
199198
}
200-
if($c==' ') {
201-
$sep=$i;
199+
if ($c==' ') {
200+
$sep = $i;
202201
}
203-
$l+=isset($cw[$c]) ? intval($cw[$c]) : 0;
204-
if($l>$wmax) {
205-
if($sep==-1) {
206-
if($i==$j) {
202+
$l += $this->GetStringWidth($c);
203+
if ($l>$wmax) {
204+
if ($sep==-1) {
205+
if ($i==$j) {
207206
$i++;
208207
}
209208
}
210209
else {
211-
$i=$sep+1;
210+
$i = $sep+1;
212211
}
213-
$sep=-1;
214-
$j=$i;
215-
$l=0;
212+
$sep = -1;
213+
$j = $i;
214+
$l = 0;
216215
$nl++;
217216
}
218217
else {

0 commit comments

Comments
 (0)