@@ -232,15 +232,19 @@ private function mergeInCascadeOrder($inherit, $tag, array $attr)
232232 $ this ->mergePresentationalHints ($ tag , $ attr );
233233 $ this ->mergeTableSpecificCss ($ tag , $ attr );
234234
235+ $ html = null ;
235236 if ($ tag === 'BODY ' ) {
236237 // Merged outside the document's elements, and written to by Mpdf::SetDefaultBodyCSS() and the like
237238 $ important = $ this ->cssManager ->getImportantCss ();
238239 $ importantDefault = $ this ->cssManager ->getDefaultImportantCss ();
239240 $ body = isset ($ this ->cssManager ->CSS ['BODY ' ]) ? $ this ->cssManager ->CSS ['BODY ' ] : [];
240241 $ this ->setMergedCss ($ body , false );
241242 $ rules = [];
242- $ importantRules = array_merge (isset ($ important ['BODY ' ]) ? [$ important ['BODY ' ]] : [], $ this ->mergeDocumentRules ());
243+ list ($ importantBody , $ html ) = $ this ->mergeDocumentRules ();
244+ $ importantRules = array_merge (isset ($ important ['BODY ' ]) ? [$ important ['BODY ' ]] : [], $ importantBody );
243245 $ importantDefaultRules = isset ($ importantDefault ['BODY ' ]) ? [$ importantDefault ['BODY ' ]] : [];
246+ // html is body's parent, which a keyword on body reads
247+ $ inherited = array_merge ($ inherited , $ html );
244248 } else {
245249 list ($ rules , $ importantRules ) = $ this ->cssManager ->getRules ()->matchingDeclarations ($ tag , $ id , $ classes , $ path );
246250 }
@@ -249,7 +253,7 @@ private function mergeInCascadeOrder($inherit, $tag, array $attr)
249253 list ($ inline , $ importantInline ) = isset ($ attr ['STYLE ' ]) ? $ this ->inlineStyleParser ->parseByImportance ($ attr ['STYLE ' ]) : [[], []];
250254 $ this ->mergeEach (array_merge ([$ inline ], $ importantRules , [$ importantInline ], $ importantDefaultRules ), $ dominance );
251255
252- $ this ->resolveWideKeywords ($ inherited , $ userAgent , $ path , $ inherit !== 'INLINE ' && $ inherit !== '' );
256+ $ this ->resolveWideKeywords ($ inherited , $ userAgent , $ path , $ inherit !== 'INLINE ' && $ inherit !== '' , $ html );
253257 if ($ this ->sideEffects ) {
254258 $ this ->mpdf ->recordStyledElementComputed ($ this ->cssProperties );
255259 }
@@ -275,9 +279,10 @@ private function mergeInCascadeOrder($inherit, $tag, array $attr)
275279 * @param callable $path Gives the open elements from the document down to the element, or null for none
276280 * @param bool $fromParent Whether an inherited property the element does not start from is read from its parent's
277281 * frame: for a block, a table and a table part
282+ * @param array|null $parentProperties The properties of a parent that has no frame, as html has none for body
278283 * @return void
279284 */
280- private function resolveWideKeywords (array $ inherited , array $ userAgent , callable $ path , $ fromParent )
285+ private function resolveWideKeywords (array $ inherited , array $ userAgent , callable $ path , $ fromParent, $ parentProperties = null )
281286 {
282287 $ parent = null ;
283288 $ sides = [];
@@ -310,7 +315,7 @@ private function resolveWideKeywords(array $inherited, array $userAgent, callabl
310315 $ resolved = $ inherited [$ property ];
311316 } elseif ($ keyword === 'inherit ' && (!$ isInherited || $ fromParent )) {
312317 if ($ parent === null ) {
313- $ parent = $ this ->parentComputed ($ path );
318+ $ parent = $ parentProperties !== null ? $ parentProperties : $ this ->parentComputed ($ path );
314319 }
315320 $ resolved = $ this ->declaredValue ($ parent , $ property );
316321 if ($ resolved === null && !$ isInherited ) {
@@ -433,7 +438,8 @@ private function initialValue($property)
433438 * html's font size, read against the default font size, is the root's, which rem and body's own size are read
434439 * against
435440 *
436- * @return array[] The !important declarations of body's rules, which apply after body's style
441+ * @return array[] The !important declarations of body's rules, which apply after body's style, and the properties
442+ * html's rules give
437443 */
438444 private function mergeDocumentRules ()
439445 {
@@ -442,6 +448,7 @@ private function mergeDocumentRules()
442448 $ initial = $ this ->mpdf ->initial_font_size ;
443449 $ this ->mpdf ->root_font_size = $ initial ;
444450
451+ $ htmlProperties = [];
445452 list ($ html , $ importantHtml ) = $ rules ->documentDeclarations (true , $ path );
446453 foreach (array_merge ($ html , $ importantHtml ) as $ properties ) {
447454 if (isset ($ properties ['FONT-SIZE ' ])) {
@@ -452,12 +459,13 @@ private function mergeDocumentRules()
452459 }
453460 }
454461 $ this ->setMergedCss ($ properties , false );
462+ $ htmlProperties = array_merge ($ htmlProperties , $ properties );
455463 }
456464
457465 list ($ body , $ importantBody ) = $ rules ->documentDeclarations (false , $ path );
458466 $ this ->mergeEach ($ body , false );
459467
460- return $ importantBody ;
468+ return [ $ importantBody, $ htmlProperties ] ;
461469 }
462470
463471 /**
0 commit comments