@@ -238,22 +238,14 @@ function print_ob_text($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
238238 $ this ->mpdf ->biDirectional = true ;
239239 }
240240
241- $ this ->mpdf -> SetLineWidth ( 0.2 / $ k );
241+ $ border = $ this ->setStaticBorder ( $ objattr , $ k );
242242
243- if (!empty ($ objattr ['disabled ' ])) {
244- $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (225 , $ this ->mpdf ->PDFAXwarnings ));
245- $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (127 , $ this ->mpdf ->PDFAXwarnings ));
246- } elseif (!empty ($ objattr ['readonly ' ])) {
247- $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (225 , $ this ->mpdf ->PDFAXwarnings ));
248- $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
249- } else {
250- $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (250 , $ this ->mpdf ->PDFAXwarnings ));
251- $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
252- }
243+ $ this ->setStaticColors ($ objattr , !empty ($ objattr ['disabled ' ]) || !empty ($ objattr ['readonly ' ]));
253244
254- $ this ->fittedCell ($ w , $ h , $ texto , 1 , $ rtlalign , 1 , $ this ->form_element_spacing ['input ' ]['inner ' ]['h ' ] / $ k );
245+ $ this ->fittedCell ($ w , $ h , $ texto , $ border ? 1 : 0 , $ rtlalign , 1 , $ this ->form_element_spacing ['input ' ]['inner ' ]['h ' ] / $ k );
255246 $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (255 , $ this ->mpdf ->PDFAXwarnings ));
256247 $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
248+ $ this ->resetStaticBorder ($ objattr );
257249 }
258250 }
259251
@@ -332,20 +324,11 @@ function print_ob_textarea($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
332324 $ this ->mpdf ->x += $ this ->form_element_spacing ['textarea ' ]['outer ' ]['h ' ] / $ k ;
333325 $ this ->mpdf ->y += $ this ->form_element_spacing ['textarea ' ]['outer ' ]['v ' ] / $ k ;
334326
335- $ this ->mpdf -> SetLineWidth ( 0.2 / $ k );
327+ $ border = $ this ->setStaticBorder ( $ objattr , $ k );
336328
337- if (!empty ($ objattr ['disabled ' ])) {
338- $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (225 , $ this ->mpdf ->PDFAXwarnings ));
339- $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (127 , $ this ->mpdf ->PDFAXwarnings ));
340- } elseif (!empty ($ objattr ['readonly ' ])) {
341- $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (225 , $ this ->mpdf ->PDFAXwarnings ));
342- $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
343- } else {
344- $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (250 , $ this ->mpdf ->PDFAXwarnings ));
345- $ this ->mpdf ->SetTColor (isset ($ objattr ['color ' ]) ? $ objattr ['color ' ] : $ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
346- }
329+ $ this ->setStaticColors ($ objattr , !empty ($ objattr ['disabled ' ]) || !empty ($ objattr ['readonly ' ]));
347330
348- $ this ->mpdf ->Rect ($ this ->mpdf ->x , $ this ->mpdf ->y , $ w , $ h , 'DF ' );
331+ $ this ->mpdf ->Rect ($ this ->mpdf ->x , $ this ->mpdf ->y , $ w , $ h , $ border ? 'DF ' : ' F ' );
349332 $ ClipPath = sprintf ('q %.3F %.3F %.3F %.3F re W n ' , $ this ->mpdf ->x * Mpdf::SCALE , ($ this ->mpdf ->h - $ this ->mpdf ->y ) * Mpdf::SCALE , $ w * Mpdf::SCALE , -$ h * Mpdf::SCALE );
350333 $ this ->writer ->write ($ ClipPath );
351334
@@ -360,6 +343,7 @@ function print_ob_textarea($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
360343 $ this ->writer ->write ('Q ' );
361344 $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (255 , $ this ->mpdf ->PDFAXwarnings ));
362345 $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
346+ $ this ->resetStaticBorder ($ objattr );
363347 }
364348 }
365349
@@ -430,14 +414,8 @@ function print_ob_select($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
430414 $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
431415
432416 } else {
433- $ this ->mpdf ->SetLineWidth (0.2 / $ k );
434- if (!empty ($ objattr ['disabled ' ])) {
435- $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (225 , $ this ->mpdf ->PDFAXwarnings ));
436- $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (127 , $ this ->mpdf ->PDFAXwarnings ));
437- } else {
438- $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (250 , $ this ->mpdf ->PDFAXwarnings ));
439- $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
440- }
417+ $ border = $ this ->setStaticBorder ($ objattr , $ k ) ? 1 : 0 ;
418+ $ this ->setStaticColors ($ objattr , !empty ($ objattr ['disabled ' ]));
441419 $ w -= $ this ->form_element_spacing ['select ' ]['outer ' ]['h ' ] * 2 / $ k ;
442420 $ h -= $ this ->form_element_spacing ['select ' ]['outer ' ]['v ' ] * 2 / $ k ;
443421 $ this ->mpdf ->x += $ this ->form_element_spacing ['select ' ]['outer ' ]['h ' ] / $ k ;
@@ -456,7 +434,7 @@ function print_ob_select($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
456434 $ this ->mpdf ->biDirectional = true ;
457435 } // *RTL*
458436
459- $ this ->fittedCell ($ w - ($ this ->mpdf ->FontSize * 1.4 ), $ h , $ texto , 1 , $ rtlalign , 1 , $ this ->form_element_spacing ['select ' ]['inner ' ]['h ' ] / $ k , $ objattr ['OTLdata ' ]);
437+ $ this ->fittedCell ($ w - ($ this ->mpdf ->FontSize * 1.4 ), $ h , $ texto , $ border , $ rtlalign , 1 , $ this ->form_element_spacing ['select ' ]['inner ' ]['h ' ] / $ k , $ objattr ['OTLdata ' ]);
460438 $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (190 , $ this ->mpdf ->PDFAXwarnings ));
461439 $ save_font = $ this ->mpdf ->FontFamily ;
462440 $ save_currentfont = $ this ->mpdf ->currentfontfamily ;
@@ -470,15 +448,16 @@ function print_ob_select($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
470448 } else {
471449 $ down = '= ' ;
472450 }
473- $ this ->mpdf ->Cell ($ this ->mpdf ->FontSize * 1.4 , $ h , $ down , 1 , 0 , 'C ' , 1 );
451+ $ this ->mpdf ->Cell ($ this ->mpdf ->FontSize * 1.4 , $ h , $ down , $ border , 0 , 'C ' , 1 );
474452 } else {
475453 $ this ->mpdf ->SetFont ('czapfdingbats ' );
476- $ this ->mpdf ->Cell ($ this ->mpdf ->FontSize * 1.4 , $ h , chr (116 ), 1 , 0 , 'C ' , 1 );
454+ $ this ->mpdf ->Cell ($ this ->mpdf ->FontSize * 1.4 , $ h , chr (116 ), $ border , 0 , 'C ' , 1 );
477455 }
478456 $ this ->mpdf ->SetFont ($ save_font );
479457 $ this ->mpdf ->currentfontfamily = $ save_currentfont ;
480458 $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (255 , $ this ->mpdf ->PDFAXwarnings ));
481459 $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
460+ $ this ->resetStaticBorder ($ objattr );
482461 }
483462 }
484463
@@ -612,15 +591,18 @@ function print_ob_button($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
612591
613592 } else {
614593
615- $ this ->mpdf ->SetLineWidth (0.2 / $ k );
616- $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (190 , $ this ->mpdf ->PDFAXwarnings ));
594+ $ border = $ this ->setStaticBorder ($ objattr , $ k );
595+ $ this ->mpdf ->SetFColor ($ this ->fieldColor ($ objattr , 'background-col ' , 190 ));
596+ if (isset ($ objattr ['color ' ])) {
597+ $ this ->mpdf ->SetTColor ($ objattr ['color ' ]);
598+ }
617599
618600 $ w -= $ this ->form_element_spacing ['button ' ]['outer ' ]['h ' ] * 2 / $ k ;
619601 $ h -= $ this ->form_element_spacing ['button ' ]['outer ' ]['v ' ] * 2 / $ k ;
620602
621603 $ this ->mpdf ->x += $ this ->form_element_spacing ['button ' ]['outer ' ]['h ' ] / $ k ;
622604 $ this ->mpdf ->y += $ this ->form_element_spacing ['button ' ]['outer ' ]['v ' ] / $ k ;
623- $ this ->mpdf ->RoundedRect ($ this ->mpdf ->x , $ this ->mpdf ->y , $ w , $ h , 0.5 / $ k , 'DF ' );
605+ $ this ->mpdf ->RoundedRect ($ this ->mpdf ->x , $ this ->mpdf ->y , $ w , $ h , 0.5 / $ k , $ border ? 'DF ' : ' F ' );
624606
625607 $ w -= $ this ->form_element_spacing ['button ' ]['inner ' ]['h ' ] * 2 / $ k ;
626608 $ h -= $ this ->form_element_spacing ['button ' ]['inner ' ]['v ' ] * 2 / $ k ;
@@ -635,6 +617,10 @@ function print_ob_button($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
635617
636618 $ this ->fittedCell ($ w , $ h , $ texto , '' , 'C ' , 0 , 0 );
637619 $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
620+ if (isset ($ objattr ['color ' ])) {
621+ $ this ->mpdf ->SetTColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
622+ }
623+ $ this ->resetStaticBorder ($ objattr );
638624 }
639625 }
640626
@@ -659,15 +645,15 @@ function print_ob_checkbox($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir, $
659645 $ ty = $ y + (($ h - $ ih ) / 2 );
660646 $ rx = $ lx + $ iw ;
661647 $ by = $ ty + $ ih ;
662- $ this ->mpdf -> SetLineWidth ( 0.2 / $ k );
648+ $ border = $ this ->setStaticBorder ( $ objattr , $ k );
663649 if (!empty ($ objattr ['disabled ' ])) {
664650 $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (225 , $ this ->mpdf ->PDFAXwarnings ));
665651 $ this ->mpdf ->SetDColor ($ this ->colorConverter ->convert (127 , $ this ->mpdf ->PDFAXwarnings ));
666652 } else {
667- $ this ->mpdf ->SetFColor ($ this ->colorConverter -> convert ( 250 , $ this -> mpdf -> PDFAXwarnings ));
668- $ this ->mpdf ->SetDColor ($ this ->colorConverter -> convert ( 0 , $ this -> mpdf -> PDFAXwarnings ));
653+ $ this ->mpdf ->SetFColor ($ this ->fieldColor ( $ objattr , ' background-col ' , 250 ));
654+ $ this ->mpdf ->SetDColor ($ this ->fieldColor ( $ objattr , ' border-col ' , 0 ));
669655 }
670- $ this ->mpdf ->Rect ($ lx , $ ty , $ iw , $ ih , 'DF ' );
656+ $ this ->mpdf ->Rect ($ lx , $ ty , $ iw , $ ih , $ border ? 'DF ' : ' F ' );
671657 if (!empty ($ objattr ['checked ' ])) {
672658 //Round join and cap
673659 $ this ->mpdf ->SetLineCap (1 );
@@ -696,30 +682,96 @@ function print_ob_radio($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir, $x,
696682 }
697683 $ this ->SetRadio ($ w , $ h , (isset ($ objattr ['fieldname ' ]) ? $ objattr ['fieldname ' ] : '' ), $ objattr ['value ' ], (isset ($ objattr ['title ' ]) ? $ objattr ['title ' ] : '' ), $ checked , $ flags , (isset ($ objattr ['disabled ' ]) ? $ objattr ['disabled ' ] : false ));
698684 } else {
699- $ this ->mpdf -> SetLineWidth ( 0.2 / $ k );
685+ $ border = $ this ->setStaticBorder ( $ objattr , $ k );
700686 $ radius = $ this ->mpdf ->FontSize * 0.35 ;
701687 $ cx = $ x + ($ w / 2 );
702688 $ cy = $ y + ($ h / 2 );
703689 $ color = $ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings );
704690 if (isset ($ objattr ['color ' ]) && $ objattr ['color ' ]) {
705691 $ color = $ objattr ['color ' ];
706692 }
693+ // The ring takes the text colour unless the border has its own
694+ $ ring = isset ($ objattr ['border-col ' ]) ? $ objattr ['border-col ' ] : $ color ;
707695 if (!empty ($ objattr ['disabled ' ])) {
708- $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (127 , $ this ->mpdf ->PDFAXwarnings ));
709- $ this ->mpdf ->SetDColor ($ this ->colorConverter ->convert (127 , $ this ->mpdf ->PDFAXwarnings ));
710- } else {
711- $ this ->mpdf ->SetFColor ($ color );
712- $ this ->mpdf ->SetDColor ($ color );
696+ $ color = $ ring = $ this ->colorConverter ->convert (127 , $ this ->mpdf ->PDFAXwarnings );
697+ }
698+ $ background = isset ($ objattr ['background-col ' ]);
699+ $ this ->mpdf ->SetFColor ($ background ? $ objattr ['background-col ' ] : $ color );
700+ $ this ->mpdf ->SetDColor ($ ring );
701+ if ($ border || $ background ) {
702+ $ this ->mpdf ->Circle ($ cx , $ cy , $ radius , ($ border ? 'D ' : '' ) . ($ background ? 'F ' : '' ));
713703 }
714- $ this ->mpdf ->Circle ($ cx , $ cy , $ radius , 'D ' );
715704 if (!empty ($ objattr ['checked ' ])) {
705+ $ this ->mpdf ->SetFColor ($ color );
706+ $ this ->mpdf ->SetDColor ($ color );
716707 $ this ->mpdf ->Circle ($ cx , $ cy , $ radius * 0.4 , 'DF ' );
717708 }
718709 $ this ->mpdf ->SetFColor ($ this ->colorConverter ->convert (255 , $ this ->mpdf ->PDFAXwarnings ));
719710 $ this ->mpdf ->SetDColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
720711 }
721712 }
722713
714+ /**
715+ * A colour the field's CSS sets, or else a default
716+ *
717+ * @param mixed[] $objattr
718+ * @param string $key 'color', 'background-col' or 'border-col'
719+ * @param int $grey the default, from 0 for black to 255 for white
720+ *
721+ * @return string
722+ */
723+ private function fieldColor (array $ objattr , $ key , $ grey )
724+ {
725+ return isset ($ objattr [$ key ]) ? $ objattr [$ key ] : $ this ->colorConverter ->convert ($ grey , $ this ->mpdf ->PDFAXwarnings );
726+ }
727+
728+ /**
729+ * Fills a text field, text area or select drawn into the page and colours its text as its CSS says, or else black
730+ * on near-white. Grey fill for a field that cannot be edited, and grey text for a disabled one, win over the CSS.
731+ *
732+ * @param mixed[] $objattr
733+ * @param bool $greyed whether it cannot be edited
734+ */
735+ private function setStaticColors (array $ objattr , $ greyed )
736+ {
737+ $ this ->mpdf ->SetFColor ($ greyed ? $ this ->colorConverter ->convert (225 , $ this ->mpdf ->PDFAXwarnings ) : $ this ->fieldColor ($ objattr , 'background-col ' , 250 ));
738+ $ this ->mpdf ->SetTColor (!empty ($ objattr ['disabled ' ]) ? $ this ->colorConverter ->convert (127 , $ this ->mpdf ->PDFAXwarnings ) : $ this ->fieldColor ($ objattr , 'color ' , 0 ));
739+ }
740+
741+ /**
742+ * Sets the line a field drawn into the page is outlined with: its CSS border width and colour, or else 0.2mm in
743+ * the colour already set. A field without a border keeps the 0.2mm line for a checkbox's cross.
744+ *
745+ * @param mixed[] $objattr
746+ * @param float $k how much a table shrinks the field
747+ *
748+ * @return bool whether the field has a border
749+ */
750+ private function setStaticBorder (array $ objattr , $ k )
751+ {
752+ $ width = isset ($ objattr ['border-width ' ]) ? $ objattr ['border-width ' ] : 0.2 ;
753+ $ border = $ width > 0 && !(isset ($ objattr ['border-style ' ]) && in_array ($ objattr ['border-style ' ], ['none ' , 'hidden ' ], true ));
754+
755+ $ this ->mpdf ->SetLineWidth (($ border ? $ width : 0.2 ) / $ k );
756+ if (isset ($ objattr ['border-col ' ])) {
757+ $ this ->mpdf ->SetDColor ($ objattr ['border-col ' ]);
758+ }
759+
760+ return $ border ;
761+ }
762+
763+ /**
764+ * Strokes in black again after a field drawn in its CSS border colour
765+ *
766+ * @param mixed[] $objattr
767+ */
768+ private function resetStaticBorder (array $ objattr )
769+ {
770+ if (isset ($ objattr ['border-col ' ])) {
771+ $ this ->mpdf ->SetDColor ($ this ->colorConverter ->convert (0 , $ this ->mpdf ->PDFAXwarnings ));
772+ }
773+ }
774+
723775 private function getCountItems ($ form )
724776 {
725777 $ total = 1 ;
0 commit comments