'pref_card_bcol' => '#53248C',
'pref_card_hcol' => '#248C53',
'pref_bool_display_title' => false,
+ 'pref_card_hsize' => 84,
+ 'pref_card_vsize' => 52,
+ 'pref_card_rows' => 6,
+ 'pref_card_cols' => 2,
'pref_card_address' => 1,
'pref_card_year' => '',
'pref_card_marges_v' => 15,
'pref_card_marges_v',
'pref_card_marges_h',
'pref_card_hspace',
- 'pref_card_vspace'
+ 'pref_card_vspace',
+ 'pref_card_hsize',
+ 'pref_card_vsize'
);
/**
$this->errors[] = _T("- The numbers and measures have to be integers!");
}
break;
+ case 'pref_card_vsize':
+ if (!is_numeric($value) || $value < 40 || $value > 55) {
+ $this->errors[] = _T("- The card height have to be an integer between 40 and 55!");
+ }
+ break;
+ case 'pref_card_hsize':
+ if (!is_numeric($value) || $value < 70 || $value > 95) {
+ $this->errors[] = _T("- The card width have to be an integer between 75 and 95!");
+ }
+ break;
case 'pref_card_tcol':
case 'pref_card_scol':
case 'pref_card_bcol':
}
$value = $v;
}
+ if ($k === 'pref_card_cols') {
+ $v = PdfMembersCards::getCols();
+ $value = $v;
+ }
+ if ($k === 'pref_card_rows') {
+ $v = PdfMembersCards::getRows();
+ $value = $v;
+ }
$stmt->execute(
array(
return null;
}
- /**
- * Check member cards sizes
- * Always a A4/portrait
- *
- * @return array<string>
- */
- public function checkCardsSizes(): array
- {
- $warning_detected = [];
- //check page width
- $max = 210;
- //margins
- $size = $this->pref_card_marges_h * 2;
- //cards
- $size += PdfMembersCards::getWidth() * PdfMembersCards::getCols();
- //spacing
- $size += $this->pref_card_hspace * (PdfMembersCards::getCols() - 1);
- if ($size > $max) {
- $warning_detected[] = _T('Current cards configuration may exceed page width!');
- }
-
- $max = 297;
- //margins
- $size = $this->pref_card_marges_v * 2;
- //cards
- $size += PdfMembersCards::getHeight() * PdfMembersCards::getRows();
- //spacing
- $size += $this->pref_card_vspace * (PdfMembersCards::getRows() - 1);
- if ($size > $max) {
- $warning_detected[] = _T('Current cards configuration may exceed page height!');
- }
-
- return $warning_detected;
- }
-
/**
* Get errors
*
class PdfMembersCards extends Pdf
{
- public const WIDTH = 75;
- public const HEIGHT = 40;
- public const COLS = 2;
- public const ROWS = 6;
+ public const PAGE_WIDTH = 210;
+ public const PAGE_HEIGHT = 297;
/** @var array<string,float|int> */
private array $tcol;
$this->vspacing = $this->preferences->pref_card_vspace;
//maximum size for visible text. May vary with fonts.
- $this->max_text_size = 80;
- $this->year_font_size = 8;
+ $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;
$print_logo = new PrintLogo();
$this->logofile = $print_logo->getPath();
- // Set logo size to max width 30mm (113px) or max height 17mm (64px)
+ // Set logo size to max 20% width or max 25% height
$ratio = $print_logo->getWidth() / $print_logo->getHeight();
if ($ratio < 1.71) {
- if ($print_logo->getHeight() > 64) {
- $this->hlogo = 17;
+ if ($print_logo->getHeight() > 0.25 * $this->wi * 3.78) {
+ $this->hlogo = round(0.25 * $this->wi);
} else {
// Convert original pixels size to millimeters
$this->hlogo = $print_logo->getHeight() / 3.78;
}
$this->wlogo = round($this->hlogo * $ratio);
} else {
- if ($print_logo->getWidth() > 113) {
- $this->wlogo = 30;
+ if ($print_logo->getWidth() > 0.2 * $this->he * 3.78) {
+ $this->wlogo = round(0.2 * $this->he);
} else {
// Convert original pixels size to millimeters
$this->wlogo = $print_logo->getWidth() / 3.78;
$photofile = $photo->getPath();
// Photo 100x130 and logo
- $this->Image($photofile, $x0, $y0, 25);
- $this->Image($this->logofile, $xl, $y0, round($this->wlogo));
+ $this->Image($photofile, $x0 + 1, $y0 + 1, round($this->wi / 3.5));
+ $this->Image($this->logofile, $xl - 1, $y0 + 1, round($this->wlogo));
// Color=#8C8C8C: Shadow of the year
$this->SetTextColor(140);
$an_cot = $member->due_date;
}
- $xan_cot = $x0 + $this->wi - $this->GetStringWidth(
+ $xan_cot = $x0 + $this->wi / 2 - $this->GetStringWidth(
$an_cot,
self::FONT,
'B',
$this->year_font_size
- ) - 0.2;
- $this->SetXY($xan_cot, $y0 + $this->hlogo - 0.3);
+ ) / 2 ;
+ $this->SetXY($xan_cot, $y0 + 1);
$this->writeHTML('<strong>' . $an_cot . '</strong>', false, false);
-
// Colored Text (Big label, id, year)
$this->SetTextColor($fcol['R'], $fcol['G'], $fcol['B']);
if (!empty($this->preferences->pref_show_id) || !empty($member->number)) {
$member_id = (!empty($member->number)) ? $member->number : $member->id;
- $xid = $x0 + $this->wi - $this->GetStringWidth($member_id, self::FONT, 'B', 8) - 0.2;
- $this->SetXY($xid, $y0 + 28);
- $this->writeHTML('<strong>' . $member_id . '</strong>', false, false);
+ $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, false);
}
$this->SetFontSize($this->year_font_size);
- $xan_cot = $xan_cot - 0.3;
- $this->SetXY($xan_cot, $y0 + $this->hlogo - 0.3);
+ $xan_cot = $xan_cot - 0.1;
+ $this->SetXY($xan_cot, $y0 + 1 - 0.1);
$this->writeHTML('<strong>' . $an_cot . '</strong>', false, false);
// Abbrev: Adapt font size to text length
12,
'B'
);
- $this->SetXY($x0 + 27, $y0 + 12);
+ $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, false);
// Name: Adapt font size to text length
8,
'B'
);
- $this->SetXY($x0 + 27, $this->getY() + 4);
+ $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, false);
6,
'B'
);
- $this->setX($x0 + 27);
+ $this->setX($x0 + round($this->wi / 3.5) + 2);
$this->writeHTML('<strong>' . $email . '</strong>', false, false);
// Lower colored strip with long text
$this->tcol['G'],
$this->tcol['B']
);
- $this->SetFont(self::FONT, 'B', 6);
- $this->SetXY($x0, $y0 + 33);
+ $this->SetFont(self::FONT, 'B', 8);
+ $this->SetXY($x0, $y0 + round($this->wi / 3.5) * 1.3 + 2);
$this->Cell(
$this->wi,
- 7,
+ ($this->he - (round($this->wi / 3.5) * 1.3 + 2)),
$this->preferences->pref_card_strip,
0,
0,
*/
public static function getWidth(): int
{
- return defined('GALETTE_CARD_WIDTH') ? GALETTE_CARD_WIDTH : self::WIDTH;
+ global $preferences;
+
+ return $preferences->pref_card_hsize ;
}
/**
*/
public static function getHeight(): int
{
- return defined('GALETTE_CARD_HEIGHT') ? GALETTE_CARD_HEIGHT : self::HEIGHT;
+ global $preferences;
+
+ return $preferences->pref_card_vsize ;
}
/**
*/
public static function getCols(): int
{
- return defined('GALETTE_CARD_COLS') ? GALETTE_CARD_COLS : self::COLS;
+ global $preferences;
+
+ $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;
}
/**
*/
public static function getRows(): int
{
- return defined('GALETTE_CARD_ROWS') ? GALETTE_CARD_ROWS : self::ROWS;
+ global $preferences;
+
+ $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;
}
}
$this->assertFalse($visible);
}
- /**
- * Data provider for cards sizes tests
- *
- * @return array
- */
- public static function sizesProvider(): array
- {
- return [
- [//defaults
- 15, //vertical margin
- 20, //horizontal margin
- 5, //vertical spacing
- 10, //horizontal spacing
- 0 //expected number of warnings
- ], [ //OK
- 0, //vertical margin
- 20, //horizontal margin
- 11, //vertical spacing
- 10, //horizontal spacing
- 0 //expected number of warnings
- ], [ //vertical overflow
- 0, //vertical margin
- 20, //horizontal margin
- 12, //vertical spacing
- 10, //horizontal spacing
- 1 //expected number of warnings
- ], [//horizontal overflow
- 15, //vertical margin
- 20, //horizontal margin
- 5, //vertical spacing
- 61, //horizontal spacing
- 1 //expected number of warnings
- ], [//vertical and horizontal overflow
- 0, //vertical margin
- 20, //horizontal margin
- 12, //vertical spacing
- 61, //horizontal spacing
- 2 //expected number of warnings
- ], [//vertical overflow
- 17, //vertical margin
- 20, //horizontal margin
- 5, //vertical spacing
- 10, //horizontal spacing
- 1 //expected number of warnings
- ]
- ];
- }
-
- /**
- * Test checkCardsSizes
- *
- * @dataProvider sizesProvider
- *
- * @param integer $vm Vertical margin
- * @param integer $hm Horizontal margin
- * @param integer $vs Vertical spacing
- * @param integer $hs Horizontal spacing
- * @param integer $count Number of expected errors
- *
- * @return void
- */
- public function testCheckCardsSizes(int $vm, int $hm, int $vs, int $hs, int $count): void
- {
- $this->preferences->pref_card_marges_v = $vm;
- $this->preferences->pref_card_marges_h = $hm;
- $this->preferences->pref_card_vspace = $vs;
- $this->preferences->pref_card_hspace = $hs;
- $this->assertCount($count, $this->preferences->checkCardsSizes());
- }
-
/**
* Data provider for colors
*