Skip to content

Commit

Permalink
phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed May 3, 2024
1 parent 011af46 commit 0f63fb0
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions galette/lib/Galette/IO/PdfMembersCards.php
Expand Up @@ -36,6 +36,9 @@

class PdfMembersCards extends Pdf
{
public const PAGE_WIDTH = 210;
public const PAGE_HEIGHT = 297;

/** @var array<string,float|int> */
private array $tcol;
/** @var array<string,float|int> */
Expand Down Expand Up @@ -129,8 +132,8 @@ public function init(): void
$this->vspacing = $this->preferences->pref_card_vspace;

//maximum size for visible text. May vary with fonts.
$this->max_text_size = self::getWidth() - round($this->wi / 3.5) - 2;
$this->year_font_size = round(self::getWidth() / 7);
$this->max_text_size = self::getWidth() - (int)round($this->wi / 3.5) - 2;
$this->year_font_size = (int)round(self::getWidth() / 7);

// Get fixed data from preferences
$this->an_cot = $this->preferences->pref_card_year;
Expand Down Expand Up @@ -252,7 +255,7 @@ public function drawCards(array $members): void
$this->year_font_size
) / 2 ;
$this->SetXY($xan_cot, $y0 + 1);
$this->writeHTML('<strong>' . $an_cot . '</strong>', false, 0);
$this->writeHTML('<strong>' . $an_cot . '</strong>', false, false);
// Colored Text (Big label, id, year)
$this->SetTextColor($fcol['R'], $fcol['G'], $fcol['B']);

Expand All @@ -262,12 +265,12 @@ public function drawCards(array $members): void
$member_id = (!empty($member->number)) ? $member->number : $member->id;
$xid = $x0 + $this->wi / 2 - $this->GetStringWidth(_T("Member") . ' n° : ' . $member_id, self::FONT, 'B', 8) / 2;
$this->SetXY($xid, $y0 + 8);
$this->writeHTML('<strong>' . _T("Member") . ' n° : ' . $member_id . ' </strong>', false, 0);
$this->writeHTML('<strong>' . _T("Member") . ' n° : ' . $member_id . ' </strong>', false, false);
}
$this->SetFontSize($this->year_font_size);
$xan_cot = $xan_cot - 0.1;
$this->SetXY($xan_cot, $y0 + 1 - 0.1);
$this->writeHTML('<strong>' . $an_cot . '</strong>', false, 0);
$this->writeHTML('<strong>' . $an_cot . '</strong>', false, false);

// Abbrev: Adapt font size to text length
$this->fixSize(
Expand All @@ -278,7 +281,7 @@ public function drawCards(array $members): void
);
$xid = $x0 + $this->wi / 2 - $this->GetStringWidth($this->abrev, self::FONT, 'B', 12) / 2;
$this->SetXY($xid, $y0 + 12);
$this->writeHTML('<strong>' . $this->abrev . '</strong>', true, 0);
$this->writeHTML('<strong>' . $this->abrev . '</strong>', true, false);

// Name: Adapt font size to text length
$this->SetTextColor(0);
Expand All @@ -290,7 +293,7 @@ public function drawCards(array $members): void
);
$this->SetXY($x0 + round($this->wi / 3.5) + 2, $y0 + $this->hlogo + 3);
//$this->setX($x0 + 27);
$this->writeHTML('<strong>' . $nom_adh_ext . '</strong>', true, 0);
$this->writeHTML('<strong>' . $nom_adh_ext . '</strong>', true, false);

// Email (adapt too)
$this->fixSize(
Expand All @@ -300,7 +303,7 @@ public function drawCards(array $members): void
'B'
);
$this->setX($x0 + round($this->wi / 3.5) + 2);
$this->writeHTML('<strong>' . $email . '</strong>', false, 0);
$this->writeHTML('<strong>' . $email . '</strong>', false, false);

// Lower colored strip with long text
$this->SetFillColor($fcol['R'], $fcol['G'], $fcol['B']);
Expand Down Expand Up @@ -360,11 +363,18 @@ public static function getCols(): int
{
global $preferences;

$nbcols = round(((210 - $preferences->pref_card_marges_h * 2) / $preferences->pref_card_hsize), 0, PHP_ROUND_HALF_DOWN) ;
if ((($nbcols - 1) * $preferences->pref_card_hspace + $preferences->pref_card_marges_h * 2 + $preferences->pref_card_hsize * $nbcols) > 210) {
$nbcols = $nbcols - 1 ;
$margins = $preferences->pref_card_marges_h * 2;

$nbcols = (int)round(
((self::PAGE_WIDTH - $margins) / $preferences->pref_card_hsize),
0,
PHP_ROUND_HALF_DOWN
);
if ((($nbcols - 1) * $preferences->pref_card_hspace + $margins + $preferences->pref_card_hsize * $nbcols) > self::PAGE_WIDTH) {
--$nbcols;
}
return $nbcols ;

return $nbcols;
}

/**
Expand All @@ -376,11 +386,17 @@ public static function getRows(): int
{
global $preferences;

$nbrows = round(((297 - $preferences->pref_card_marges_v * 2) / $preferences->pref_card_vsize), 0, PHP_ROUND_HALF_DOWN) ;
if ((($nbrows - 1) * $preferences->pref_card_vspace + $preferences->pref_card_marges_v * 2 + $preferences->pref_card_vsize * $nbrows) > 297) {
$nbrows = $nbrows - 1 ;
$margins = $preferences->pref_card_marges_v * 2;

$nbrows = (int)round(
((self::PAGE_HEIGHT - $margins) / $preferences->pref_card_vsize),
0,
PHP_ROUND_HALF_DOWN
);
if ((($nbrows - 1) * $preferences->pref_card_vspace + $margins + $preferences->pref_card_vsize * $nbrows) > self::PAGE_HEIGHT) {
--$nbrows;
}

return $nbrows ;
return $nbrows;
}
}

0 comments on commit 0f63fb0

Please sign in to comment.