Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

min-height & max-height not working #476

Closed
PhenX opened this issue Dec 6, 2012 · 6 comments
Closed

min-height & max-height not working #476

PhenX opened this issue Dec 6, 2012 · 6 comments

Comments

@PhenX
Copy link
Member

PhenX commented Dec 6, 2012

Original author: johngbel...@gmail.com (April 24, 2012 19:26:20)

What steps will reproduce the problem?
<div style="min-height:100px">...</div>

What is the expected output? What do you see instead?
expected: 100px high div
seen: div shrunk to content

What version of dompdf are you using? What version of PHP? On what
operating system?
Trunk, Php 5.3.10, Centos

Please provide the HTML source code you want to convert, or any additional
information.

will work on patch

Original issue: http://code.google.com/p/dompdf/issues/detail?id=470

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From fabien.menager on April 24, 2012 20:19:08
This is the related discussion thread: http://groups.google.com/group/dompdf/browse_thread/thread/206659b72d0e6bfc/3c0d538cab3400c0?show_docid=3c0d538cab3400c0

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From johngbel...@gmail.com on April 28, 2012 08:28:02
I have re-named _calculate_restricted_height() to _calculate_height() to be consistent with the width methods, and moved the max_height/min_height calculations to a new _calculate_restricted_height() method in Frame_Reflower. That way, other reflower classes can use the same method.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From turbop....@gmail.com on May 08, 2012 10:12:50
The 2 file block_frame_reflower.patch and frame_reflower.patch is same.
Please add the frame_reflower.patch file correctly.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From johngbel...@gmail.com on May 15, 2012 21:36:53
corrected file attached

@bsweeney
Copy link
Member

patch files from original issue on Google Code:

block_frame_reflower.patch:

# This patch file was generated by NetBeans IDE
--
# Following Index: paths are relative to: C:\Users\john\Documents\dev\dompdf\dompdf\include
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: block_frame_reflower.cls.php
--- block_frame_reflower.cls.php Base (BASE)
+++ block_frame_reflower.cls.php Locally Modified (Based On LOCAL)
@@ -224,7 +224,7 @@
* Determine the frame's restricted height
* @return array
*/
-  protected function _calculate_restricted_height() {
+  protected function _calculate_height() {
$frame = $this->_frame;
$style = $frame->get_style();
$content_height = $this->_calculate_content_height();
@@ -349,49 +349,12 @@
} else {
 
// Expand the height if overflow is visible
-      if ( $height === "auto" && $content_height > $height /* && $style->overflow === "visible" */)
+      if ( $height === "auto" && $content_height > $height  && $style->overflow === "visible" )
$height = $content_height;
 
-      // FIXME: this should probably be moved to a seperate function as per
-      // _calculate_restricted_width
-
-      // Only handle min/max height if the height is independent of the frame's content
-      if ( !($style->overflow === "visible" \|\|
-             ($style->overflow === "hidden" && $height === "auto")) ) {
-
-        $min_height = $style->min_height;
-        $max_height = $style->max_height;
-
-        if ( isset($cb["h"]) ) {
-          $min_height = $style->length_in_pt($min_height, $cb["h"]);
-          $max_height = $style->length_in_pt($max_height, $cb["h"]);
-
-        } else if ( isset($cb["w"]) ) {
-
-          if ( mb_strpos($min_height, "%") !== false )
-            $min_height = 0;
-          else
-            $min_height = $style->length_in_pt($min_height, $cb["w"]);
-
-          if ( mb_strpos($max_height, "%") !== false )
-            $max_height = "none";
-          else
-            $max_height = $style->length_in_pt($max_height, $cb["w"]);
+	  $height = $this->_calculate_restricted_height($height);
}
 
-        if ( $max_height !== "none" && $min_height > $max_height )
-          // Swap 'em
-          list($max_height, $min_height) = array($min_height, $max_height);
-
-        if ( $max_height !== "none" && $height > $max_height )
-          $height = $max_height;
-
-        if ( $height < $min_height )
-          $height = $min_height;
-      }
-
-    }
-
return array($height, $margin_top, $margin_bottom, $top, $bottom);
 
}
@@ -737,7 +700,7 @@
}
 
// Determine our height
-    list($height, $margin_top, $margin_bottom, $top, $bottom) = $this->_calculate_restricted_height();
+    list($height, $margin_top, $margin_bottom, $top, $bottom) = $this->_calculate_height();
$style->height = $height;
$style->margin_top = $margin_top;
$style->margin_bottom = $margin_bottom;

frame_reflower.patch:

# This patch file was generated by NetBeans IDE
--
# Following Index: paths are relative to: C:\Users\john\Documents\dev\dompdf\dompdf\include
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: frame_reflower.cls.php
--- frame_reflower.cls.php Base (BASE)
+++ frame_reflower.cls.php Locally Modified (Based On LOCAL)
@@ -411,4 +411,55 @@
$frame->append_child($new_frame);
}
}
+
+  /*
+   * modify height based on max_heigh and min_height
+   * http://www.w3.org/TR/CSS21/visudet.html#min-max-heights
+   *
+   * @param mixed height
+   *
+   * @return corrected height
+   */
+  protected function _calculate_restricted_height($height){
+    $frame = $this->_frame;
+    $style = $frame->get_style();
+    $cb = $frame->get_containing_block();
+
+    if ( isset($cb["h"]) ) {
+      $min_height = $style->length_in_pt($style->min_height, $cb["h"]);
+      $max_height = $style->length_in_pt($style->max_height, $cb["h"]);
+    } else {
+      /* The percentage is calculated with respect to the height of the generated box's containing block.
+       * If the height of the containing block is not specified explicitly
+       * (i.e., it depends on content height), and this element is not absolutely positioned,
+       * the percentage value is treated as '0' (for 'min-height') or 'none' (for 'max-height').
+       */
+      if ( mb_strpos($min_height, "%") !== false ){
+        $min_height = 0;
+      } else {
+        $min_height = $style->length_in_pt($style->min_height);
}
+
+      if ( mb_strpos($max_height, "%") !== false ) {
+        $max_height = "none";
+      } else {
+        $max_height = $style->length_in_pt($style->max_height);
+      }
+    }
+
+    //values cannot be negative
+    if ($min_height < 0 ) $min_height = 0;
+    if ($max_height < 0 ) $max_height = "none";
+
+    // Only handle max height if the height is independent of the frame's content
+    if ( $max_height !== "none" && $height > $max_height && $style->overflow !== "visible" )
+      $height = $max_height;
+
+    if ( $height < $min_height )
+      $height = $min_height;
+
+    return $height;
+
+  }
+
+}

@bsweeney bsweeney added this to the 1.1.0 milestone Nov 4, 2021
@bsweeney
Copy link
Member

bsweeney commented Nov 4, 2021

This issue has been addressed for the upcoming release.

@bsweeney bsweeney closed this as completed Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants