From c0c555b78f38496e954f75a77fc9cebec7ab4a11 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Wed, 8 Jan 2014 15:16:56 +0100
Subject: [PATCH] Fix: A lot of fix into sticker sheet dimension management.
 Fix: Size of font too large to print sticker pages.

Conflicts:
	htdocs/core/modules/member/doc/pdf_standard.class.php
	htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php
---
 htdocs/core/lib/format_cards.lib.php          | 76 ++++++++++---------
 .../modules/member/doc/pdf_standard.class.php | 18 +++--
 .../doc/pdf_standardlabel.class.php           | 18 +++--
 3 files changed, 64 insertions(+), 48 deletions(-)

diff --git a/htdocs/core/lib/format_cards.lib.php b/htdocs/core/lib/format_cards.lib.php
index 5f18cb1a976..e45ff13be59 100644
--- a/htdocs/core/lib/format_cards.lib.php
+++ b/htdocs/core/lib/format_cards.lib.php
@@ -27,56 +27,59 @@
 
 global $_Avery_Labels;
 
-
+// Unit of metric are defined into field 'metric' in mm.
+// To get into inch, just /25.4
+// Size of pages available on: http://www.worldlabel.com/Pages/pageaverylabels.htm
+// _PosX = marginLeft+(_COUNTX*(width+SpaceX));
 $_Avery_Labels = array (
-			      '5160'=>array('name'=>'5160 (Letter)',
+			      '5160'=>array('name'=>'Avery-5160, WL-875WX',
 					    'paper-size'=>'letter',
 					    'metric'=>'mm',
-					    'marginLeft'=>1.762,
-					    'marginTop'=>10.7,
+					    'marginLeft'=>5.58165,	// 0.21975 inch
+					    'marginTop'=>12.7,		// 0.5 inch
 					    'NX'=>3,
 					    'NY'=>10,
-					    'SpaceX'=>3.175,
+					    'SpaceX'=>3.556,	// 0.14 inch
 					    'SpaceY'=>0,
-					    'width'=>66.675,
-					    'height'=>25.4,
-					    'font-size'=>8),
-			      '5161'=>array('name'=>'5161 (Letter)',
+					    'width'=>65.8749,	// 2.59350 inch
+					    'height'=>25.4,		// 1 inch
+					    'font-size'=>7),
+			      '5161'=>array('name'=>'Avery-5161, WL-75WX',
 					    'paper-size'=>'letter',
 					    'metric'=>'mm',
-					    'marginLeft'=>0.967,
-					    'marginTop'=>10.7,
+					    'marginLeft'=>4.445,	// 0.175 inch
+					    'marginTop'=>12.7,
 					    'NX'=>2,
 					    'NY'=>10,
-					    'SpaceX'=>3.967,
+					    'SpaceX'=>3.968,	// 0.15625 inch
 					    'SpaceY'=>0,
-					    'width'=>101.6,
-					    'height'=>25.4,
-					    'font-size'=>8),
-			      '5162'=>array('name'=>'5162 (Letter)',
+					    'width'=>101.6,		// 4 inch
+					    'height'=>25.4,		// 1 inch
+					    'font-size'=>7),
+			      '5162'=>array('name'=>'Avery-5162, WL-100WX',
 					    'paper-size'=>'letter',
 					    'metric'=>'mm',
-					    'marginLeft'=>0.97,
-					    'marginTop'=>20.224,
+					    'marginLeft'=>3.8735,	// 0.1525 inch
+					    'marginTop'=>22.352,	// 0.88 inch
 					    'NX'=>2,
 					    'NY'=>7,
-					    'SpaceX'=>4.762,
+					    'SpaceX'=>4.954,	// 0.195 inch
 					    'SpaceY'=>0,
-					    'width'=>100.807,
-					    'height'=>35.72,
+					    'width'=>101.6,		// 4 inch
+					    'height'=>33.781,	// 1.33 inch
 					    'font-size'=>8),
-			      '5163'=>array('name'=>'5163 (Letter)',
+			      '5163'=>array('name'=>'Avery-5163, WL-125WX',
 					    'paper-size'=>'letter',
 					    'metric'=>'mm',
-					    'marginLeft'=>1.762,
-					    'marginTop'=>10.7,
+					    'marginLeft'=>4.572,	// 0.18 inch
+					    'marginTop'=>12.7,	// 0.5 inch
 					    'NX'=>2,
 					    'NY'=>5,
-					    'SpaceX'=>3.175,
+					    'SpaceX'=>3.556,	// 0.14 inch
 					    'SpaceY'=>0,
-					    'width'=>101.6,
-					    'height'=>50.8,
-					    'font-size'=>8),
+					    'width'=>101.6,		// 4 inch
+					    'height'=>50.8,		// 2 inch
+					    'font-size'=>10),
 			     /* Bugged '5164'=>array('name'=>'5164 (Letter)',
 					    'paper-size'=>'letter',
 					    'metric'=>'in',
@@ -89,7 +92,7 @@ $_Avery_Labels = array (
 					    'width'=>4.0,
 					    'height'=>3.33,
 					    'font-size'=>12), */
-			      '8600'=>array('name'=>'8600 (Letter)',
+			      '8600'=>array('name'=>'Avery-8600',
 					    'paper-size'=>'letter',
 					    'metric'=>'mm',
 					    'marginLeft'=>7.1,
@@ -100,8 +103,8 @@ $_Avery_Labels = array (
 					    'SpaceY'=>3.1,
 					    'width'=>66.6,
 					    'height'=>25.4,
-					    'font-size'=>8),
-			      'L7163'=>array('name'=>'L7163 (A4)',
+					    'font-size'=>7),
+			      'L7163'=>array('name'=>'Avery-L7163',
 					     'paper-size'=>'A4',
 					     'metric'=>'mm',
 					     'marginLeft'=>5,
@@ -112,8 +115,9 @@ $_Avery_Labels = array (
 					     'SpaceY'=>0,
 					     'width'=>99.1,
 					     'height'=>38.1,
-					     'font-size'=>10),
-			      'AVERYC32010'=>array('name'=>'AVERY-C32010 (A4)',
+					     'font-size'=>8),
+					// 85.0 x 54.0 mm
+			      'AVERYC32010'=>array('name'=>'Avery-C32010',
 					     'paper-size'=>'A4',
 					     'metric'=>'mm',
 					     'marginLeft'=>15,
@@ -125,7 +129,7 @@ $_Avery_Labels = array (
 					     'width'=>85,
 					     'height'=>54,
 					     'font-size'=>10),
-					'CARD'=>array('name'=>'Dolibarr Business cards (A4)',
+					'CARD'=>array('name'=>'Dolibarr Business cards',
 					    'paper-size'=>'A4',
 					    'metric'=>'mm',
 					    'marginLeft'=>15,
@@ -139,5 +143,9 @@ $_Avery_Labels = array (
 					    'font-size'=>10)
 		);
 
+foreach($_Avery_Labels as $key => $val)
+{
+	$_Avery_Labels[$key]['name'].=' ('.$_Avery_Labels[$key]['paper-size'].' - '.$_Avery_Labels[$key]['NX'].'x'.$_Avery_Labels[$key]['NY'].')';
+}
 
 ?>
\ No newline at end of file
diff --git a/htdocs/core/modules/member/doc/pdf_standard.class.php b/htdocs/core/modules/member/doc/pdf_standard.class.php
index 00aba591add..4f8e909d2b1 100644
--- a/htdocs/core/modules/member/doc/pdf_standard.class.php
+++ b/htdocs/core/modules/member/doc/pdf_standard.class.php
@@ -114,7 +114,9 @@ class pdf_standard
 
 
 	/**
-	 * On imprime une etiquette
+	 * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)
+	 * - %LOGO% is replace with company logo
+	 * - %PHOTO% is replace with photo provided as parameter
 	 *
 	 * @param    PDF	    &$pdf		    PDF
 	 * @param    string     $textleft       Textleft
@@ -184,25 +186,27 @@ class pdf_standard
 			$pdf->image($backgroundimage,$_PosX,$_PosY,$this->_Width,$this->_Height);
 		}
 
+		$xleft=2; $ytop=2;
+
 		// Top
 		if ($header!='')
 		{
 			if ($this->code == "CARD")
 			{
 				$pdf->SetDrawColor(128,128,128);
-				$pdf->Line($_PosX, $_PosY+$this->_Line_Height+1, $_PosX+$this->_Width, $_PosY+$this->_Line_Height+1);
+				$pdf->Line($_PosX, $_PosY+$this->_Line_Height+1, $_PosX+$this->_Width, $_PosY+$this->_Line_Height+1); // Only 1 mm and not ytop for top text
 				$pdf->SetDrawColor(0,0,0);
 			}
-			$pdf->SetXY($_PosX, $_PosY+1);
-			$pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($header),0,1,'C');
+			$pdf->SetXY($_PosX+$xleft, $_PosY+1); // Only 1 mm and not ytop for top text
+			$pdf->Cell($this->_Width-2*$xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header),0,1,'C');
 		}
 
 
-		$xleft=2; $ytop=2+(empty($header)?0:1+$this->_Line_Height);
-		$maxwidthtouse=round(($this->_Width - 2*$xleft)*$imgscalewidth); $maxheighttouse=round(($this->_Height - 2*$ytop)*$imgscaleheight);
-		$defaultratio=($maxwidthtouse/$maxheighttouse);
+		$ytop+=(empty($header)?0:(1+$this->_Line_Height));
 
 		// Define widthtouse and heighttouse
+		$maxwidthtouse=round(($this->_Width - 2*$xleft)*$imgscalewidth); $maxheighttouse=round(($this->_Height - 2*$ytop)*$imgscaleheight);
+		$defaultratio=($maxwidthtouse/$maxheighttouse);
 		$widthtouse=$maxwidthtouse; $heighttouse=0;		// old value for image
 		$tmp=dol_getImageSize($photo, false);
 		if ($tmp['height'])
diff --git a/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php b/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php
index c05f168d2a8..9c6d1eb3353 100644
--- a/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php
+++ b/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php
@@ -113,7 +113,9 @@ class pdf_standardlabel
 	}
 
 	/**
-	 * On imprime une etiquette
+	 * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)
+	 * - %LOGO% is replace with company logo
+	 * - %PHOTO% is replace with photo provided as parameter
 	 *
 	 * @param   PDF	    	&$pdf		    PDF
 	 * @param   string		$textleft       Text left
@@ -172,25 +174,27 @@ class pdf_standardlabel
 			$pdf->image($backgroundimage,$_PosX,$_PosY,$this->_Width,$this->_Height);
 		}
 
+		$xleft=2; $ytop=2;
+
 		// Top
 		if ($header!='')
 		{
 			if ($this->code == "CARD")
 			{
 				$pdf->SetDrawColor(128,128,128);
-				$pdf->Line($_PosX, $_PosY+$this->_Line_Height+1, $_PosX+$this->_Width, $_PosY+$this->_Line_Height+1);
+				$pdf->Line($_PosX, $_PosY+$this->_Line_Height+1, $_PosX+$this->_Width, $_PosY+$this->_Line_Height+1); // Only 1 mm and not ytop for top text
 				$pdf->SetDrawColor(0,0,0);
 			}
-			$pdf->SetXY($_PosX, $_PosY+1);
-			$pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($header),0,1,'C');
+			$pdf->SetXY($_PosX+$xleft, $_PosY+1); // Only 1 mm and not ytop for top text
+			$pdf->Cell($this->_Width-2*$xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header),0,1,'C');
 		}
 
 
-		$xleft=2; $ytop=2+(empty($header)?0:1+$this->_Line_Height);
-		$maxwidthtouse=round(($this->_Width - 2*$xleft)*$imgscalewidth); $maxheighttouse=round(($this->_Height - 2*$ytop)*$imgscaleheight);
-		$defaultratio=($maxwidthtouse/$maxheighttouse);
+		$ytop+=(empty($header)?0:(1+$this->_Line_Height));
 
 		// Define widthtouse and heighttouse
+		$maxwidthtouse=round(($this->_Width - 2*$xleft)*$imgscalewidth); $maxheighttouse=round(($this->_Height - 2*$ytop)*$imgscaleheight);
+		$defaultratio=($maxwidthtouse/$maxheighttouse);
 		$widthtouse=$maxwidthtouse; $heighttouse=0;		// old value for image
 		$tmp=dol_getImageSize($photo, false);
 		if ($tmp['height'])
-- 
GitLab