@@ -59,23 +59,44 @@ public function write($pdf, $record)
5959 $ currentX += $ barcodeSize + self ::BARCODE_MARGIN ;
6060 $ usableWidth -= $ barcodeSize + self ::BARCODE_MARGIN ;
6161 }
62+ $ fields = $ record ->get ('fields ' );
63+ // Below rescales the size of the field box to fit, it feels like it could/should be abstracted one class above
64+ // to be usable on other labels but im unsure of how to implement that, since it uses a lot of private
65+ // constants.
6266
63- foreach ($ record ->get ('fields ' ) as $ field ) {
67+ // Figure out how tall the label fields wants to be
68+ $ fieldCount = count ($ fields );
69+ $ perFieldHeight = (self ::LABEL_SIZE + self ::LABEL_MARGIN )
70+ + (self ::FIELD_SIZE + self ::FIELD_MARGIN );
71+
72+ $ baseHeight = $ fieldCount * $ perFieldHeight ;
73+ // If it doesn't fit in the available height, scale everything down
74+ $ scale = 1.0 ;
75+ if ($ baseHeight > $ usableHeight && $ baseHeight > 0 ) {
76+ $ scale = $ usableHeight / $ baseHeight ;
77+ }
78+
79+ $ labelSize = self ::LABEL_SIZE * $ scale ;
80+ $ labelMargin = self ::LABEL_MARGIN * $ scale ;
81+ $ fieldSize = self ::FIELD_SIZE * $ scale ;
82+ $ fieldMargin = self ::FIELD_MARGIN * $ scale ;
83+
84+ foreach ($ fields as $ field ) {
6485 static ::writeText (
6586 $ pdf , $ field ['label ' ],
6687 $ currentX , $ currentY ,
67- 'freesans ' , '' , self :: LABEL_SIZE , 'L ' ,
68- $ usableWidth , self :: LABEL_SIZE , true , 0
88+ 'freesans ' , '' , $ labelSize , 'L ' ,
89+ $ usableWidth , $ labelSize , true , 0
6990 );
70- $ currentY += self :: LABEL_SIZE + self :: LABEL_MARGIN ;
91+ $ currentY += $ labelSize + $ labelMargin ;
7192
7293 static ::writeText (
7394 $ pdf , $ field ['value ' ],
7495 $ currentX , $ currentY ,
75- 'freemono ' , 'B ' , self :: FIELD_SIZE , 'L ' ,
76- $ usableWidth , self :: FIELD_SIZE , true , 0 , 0.01
96+ 'freemono ' , 'B ' , $ fieldSize , 'L ' ,
97+ $ usableWidth , $ fieldSize , true , 0 , 0.01
7798 );
78- $ currentY += self :: FIELD_SIZE + self :: FIELD_MARGIN ;
99+ $ currentY += $ fieldSize + $ fieldMargin ;
79100 }
80101 }
81102}
0 commit comments