@@ -953,7 +953,7 @@ public function newPage(array $settings = [])
953953 * feed int; x position (required)
954954 * font string; font style, optional: bold, italic, regular
955955 * font_file string; path to font file (optional for use your custom font)
956- * font_size int; font size (default 7 )
956+ * font_size int; font size (default 10 )
957957 * align string; text align (also see feed parametr), optional left, right
958958 * height int;line spacing (default 10)
959959 *
@@ -1005,24 +1005,8 @@ public function drawLineBlocks(\Zend_Pdf_Page $page, array $draw, array $pageSet
10051005 foreach ($ lines as $ line ) {
10061006 $ maxHeight = 0 ;
10071007 foreach ($ line as $ column ) {
1008- $ fontSize = empty ($ column ['font_size ' ]) ? 10 : $ column ['font_size ' ];
1009- if (!empty ($ column ['font_file ' ])) {
1010- $ font = \Zend_Pdf_Font::fontWithPath ($ column ['font_file ' ]);
1011- $ page ->setFont ($ font , $ fontSize );
1012- } else {
1013- $ fontStyle = empty ($ column ['font ' ]) ? 'regular ' : $ column ['font ' ];
1014- switch ($ fontStyle ) {
1015- case 'bold ' :
1016- $ font = $ this ->_setFontBold ($ page , $ fontSize );
1017- break ;
1018- case 'italic ' :
1019- $ font = $ this ->_setFontItalic ($ page , $ fontSize );
1020- break ;
1021- default :
1022- $ font = $ this ->_setFontRegular ($ page , $ fontSize );
1023- break ;
1024- }
1025- }
1008+ $ font = $ this ->setFont ($ page , $ column );
1009+ $ fontSize = $ column ['font_size ' ];
10261010
10271011 if (!is_array ($ column ['text ' ])) {
10281012 $ column ['text ' ] = [$ column ['text ' ]];
@@ -1033,6 +1017,8 @@ public function drawLineBlocks(\Zend_Pdf_Page $page, array $draw, array $pageSet
10331017 foreach ($ column ['text ' ] as $ part ) {
10341018 if ($ this ->y - $ lineSpacing < 15 ) {
10351019 $ page = $ this ->newPage ($ pageSettings );
1020+ $ font = $ this ->setFont ($ page , $ column );
1021+ $ fontSize = $ column ['font_size ' ];
10361022 }
10371023
10381024 $ feed = $ column ['feed ' ];
@@ -1066,4 +1052,42 @@ public function drawLineBlocks(\Zend_Pdf_Page $page, array $draw, array $pageSet
10661052
10671053 return $ page ;
10681054 }
1055+
1056+ /**
1057+ * Set page font.
1058+ *
1059+ * column array format
1060+ * font string; font style, optional: bold, italic, regular
1061+ * font_file string; path to font file (optional for use your custom font)
1062+ * font_size int; font size (default 10)
1063+ *
1064+ * @param \Zend_Pdf_Page $page
1065+ * @param array $column
1066+ * @return \Zend_Pdf_Resource_Font
1067+ * @throws \Zend_Pdf_Exception
1068+ */
1069+ private function setFont ($ page , &$ column )
1070+ {
1071+ $ fontSize = empty ($ column ['font_size ' ]) ? 10 : $ column ['font_size ' ];
1072+ $ column ['font_size ' ] = $ fontSize ;
1073+ if (!empty ($ column ['font_file ' ])) {
1074+ $ font = \Zend_Pdf_Font::fontWithPath ($ column ['font_file ' ]);
1075+ $ page ->setFont ($ font , $ fontSize );
1076+ } else {
1077+ $ fontStyle = empty ($ column ['font ' ]) ? 'regular ' : $ column ['font ' ];
1078+ switch ($ fontStyle ) {
1079+ case 'bold ' :
1080+ $ font = $ this ->_setFontBold ($ page , $ fontSize );
1081+ break ;
1082+ case 'italic ' :
1083+ $ font = $ this ->_setFontItalic ($ page , $ fontSize );
1084+ break ;
1085+ default :
1086+ $ font = $ this ->_setFontRegular ($ page , $ fontSize );
1087+ break ;
1088+ }
1089+ }
1090+
1091+ return $ font ;
1092+ }
10691093}
0 commit comments