@@ -416,7 +416,7 @@ function print_ob_select($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
416416 $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
417417 }
418418
419- $ this ->SetFormChoice ($ w , $ h , (isset ($ objattr ['fieldname ' ]) ? $ objattr ['fieldname ' ] : '' ), $ flags , $ data , $ rtlalign , $ js , (isset ($ objattr ['background-col ' ]) ? $ objattr ['background-col ' ] : false ), (isset ($ objattr ['border-col ' ]) ? $ objattr ['border-col ' ] : false ), $ this ->activeBorder ($ objattr ));
419+ $ this ->SetFormChoice ($ w , $ h , (isset ($ objattr ['fieldname ' ]) ? $ objattr ['fieldname ' ] : '' ), $ flags , $ data , $ rtlalign , $ js , (isset ($ objattr ['background-col ' ]) ? $ objattr ['background-col ' ] : false ), (isset ($ objattr ['border-col ' ]) ? $ objattr ['border-col ' ] : false ), $ this ->activeBorder ($ objattr ), ( isset ( $ objattr [ ' rows ' ]) ? $ objattr [ ' rows ' ] : 1 ) );
420420 $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
421421
422422 } else {
@@ -1199,7 +1199,7 @@ function SetFormText($w, $h, $name, $value = '', $default = '', $title = '', $fl
11991199 }
12001200 }
12011201
1202- function SetFormChoice ($ w , $ h , $ name , $ flags , $ array , $ align = 'L ' , $ js = '' , $ background_col = false , $ border_col = false , $ border = [])
1202+ function SetFormChoice ($ w , $ h , $ name , $ flags , $ array , $ align = 'L ' , $ js = '' , $ background_col = false , $ border_col = false , $ border = [], $ rows = 1 )
12031203 {
12041204 $ this ->formCount ++;
12051205 if ($ this ->mpdf ->blk [$ this ->mpdf ->blklvl ]['direction ' ] === 'rtl ' ) {
@@ -1214,7 +1214,7 @@ function SetFormChoice($w, $h, $name, $flags, $array, $align = 'L', $js = '', $b
12141214 if (in_array (self ::FLAG_COMBOBOX , $ flags , true )) {
12151215 $ appearance = $ this ->appearanceText ($ w , $ h , $ border ['W ' ], [$ array ['SEL ' ] ? $ array ['OPT ' ][$ array ['SEL ' ][0 ]] : '' ], $ align , 'line ' );
12161216 } else {
1217- $ appearance = $ this ->appearanceText ($ w , $ h , $ border ['W ' ], $ array ['OPT ' ], $ align , 'list ' , $ array ['SEL ' ]);
1217+ $ appearance = $ this ->appearanceText ($ w , $ h , $ border ['W ' ], $ array ['OPT ' ], $ align , 'list ' , $ array ['SEL ' ], true , $ rows );
12181218 }
12191219 if ($ this ->mpdf ->onlyCoreFonts ) {
12201220 for ($ i = 0 ; $ i < count ($ array ['VAL ' ]); $ i ++) {
@@ -1689,16 +1689,17 @@ private function fitLine($size, $room, $length, $measure)
16891689 * @param float $border its border width, in points
16901690 * @param string[] $lines the text, a line each, in the document's encoding
16911691 * @param string $align '0', '1' or '2', left, centred or right as /Q has it
1692- * @param string $flow 'line' centres the first line on the height, 'wrap' runs the lines down from the top
1693- * wrapped to the width, and 'list' runs them down unwrapped, as a list box shows its options
1692+ * @param string $flow 'line' centres the first line on the height, 'wrap' runs the lines down from the top wrapped
1693+ * to the width, and 'list' shows them unwrapped a row each , as a list box shows its options
16941694 * @param int[] $selected the lines a list box highlights
16951695 * @param bool $fit whether a 'line' is fitted to the widget as fitLine() does. Not for a hidden field, which has no
16961696 * room, or a button that shows an icon instead
1697+ * @param int $rows the rows a list box shows
16971698 *
16981699 * @return mixed[] the font size, each line with where it starts and as the font encodes it, and the highlights, in
16991700 * points from the bottom left
17001701 */
1701- private function appearanceText ($ w , $ h , $ border , array $ lines , $ align , $ flow , array $ selected = [], $ fit = true )
1702+ private function appearanceText ($ w , $ h , $ border , array $ lines , $ align , $ flow , array $ selected = [], $ fit = true , $ rows = 1 )
17021703 {
17031704 if (!$ this ->mpdf ->usingCoreFont && !$ this ->complexText ) {
17041705 foreach ($ lines as $ line ) {
@@ -1730,23 +1731,40 @@ private function appearanceText($w, $h, $border, array $lines, $align, $flow, ar
17301731 });
17311732 $ lines = [mb_substr ($ line , 0 , $ length , $ this ->mpdf ->mb_enc )];
17321733 }
1734+
1735+ // A list box's rows share the height inside the border. Tag\Select allowed one font size a row, less than the
1736+ // font's line height, so the font shrinks to keep each row whole
1737+ $ rowHeight = ($ height - 2 * $ border ) / $ rows ;
1738+ if ($ flow === 'list ' ) {
1739+ $ size = min ($ size , $ rowHeight / ($ ascent - $ descent ));
1740+ }
17331741 $ leading = ($ ascent - $ descent ) * $ size ;
17341742
17351743 $ top = 0 ;
17361744 if ($ flow === 'wrap ' ) {
17371745 $ lines = $ this ->wrap ($ lines , $ room / $ size );
1738- } elseif ($ flow === ' line ' ) {
1746+ } elseif ($ flow !== ' list ' ) {
17391747 $ lines = array_slice ($ lines , 0 , 1 );
1740- } elseif ($ selected && min ($ selected ) >= floor (( $ height - 2 * $ padding ) / $ leading ) ) {
1748+ } elseif ($ selected && min ($ selected ) >= $ rows ) {
17411749 // A list box too short to show its first selected option starts at it
17421750 $ top = min ($ selected );
17431751 }
17441752
17451753 $ layout = ['size ' => $ size , 'lines ' => [], 'highlights ' => []];
1746- foreach (array_slice ($ lines , $ top , null , true ) as $ i => $ line ) {
1747- $ y = $ flow === 'line ' ? ($ height - $ leading ) / 2 - $ descent * $ size : $ height - $ padding - $ ascent * $ size - ($ i - $ top ) * $ leading ;
1748- if ($ y + $ ascent * $ size < 0 ) {
1749- break ;
1754+ foreach (array_slice ($ lines , $ top , $ flow === 'list ' ? $ rows : null , true ) as $ i => $ line ) {
1755+ if ($ flow === 'list ' ) {
1756+ $ rowBottom = $ height - $ border - ($ i - $ top + 1 ) * $ rowHeight ;
1757+ $ y = $ rowBottom + ($ rowHeight - $ leading ) / 2 - $ descent * $ size ;
1758+ if (in_array ($ i , $ selected , true )) {
1759+ $ layout ['highlights ' ][] = [$ border , $ rowBottom , $ width - 2 * $ border , $ rowHeight ];
1760+ }
1761+ } elseif ($ flow === 'wrap ' ) {
1762+ $ y = $ height - $ padding - $ ascent * $ size - $ i * $ leading ;
1763+ if ($ y + $ ascent * $ size < 0 ) {
1764+ break ;
1765+ }
1766+ } else {
1767+ $ y = ($ height - $ leading ) / 2 - $ descent * $ size ;
17501768 }
17511769
17521770 $ lineWidth = $ this ->emWidth ($ line ) * $ size ;
@@ -1759,9 +1777,6 @@ private function appearanceText($w, $h, $border, array $lines, $align, $flow, ar
17591777 }
17601778
17611779 $ layout ['lines ' ][] = [$ x , $ y , $ this ->mpdf ->usingCoreFont ? $ line : $ this ->writer ->utf8ToUtf16BigEndian ($ line , false )];
1762- if (in_array ($ i , $ selected , true )) {
1763- $ layout ['highlights ' ][] = [$ border , $ y + $ descent * $ size , $ width - 2 * $ border , $ leading ];
1764- }
17651780 }
17661781
17671782 return $ layout ;
0 commit comments