function get_min_max_width() { $style = $this->_frame->get_style(); $this->_block_parent = $this->_frame->find_block_parent(); $line_width = $this->_frame->get_containing_block("w"); $str = $text = $this->_frame->get_text(); $size = $style->font_size; $font = $style->font_family; $word_spacing = $style->length_in_pt($style->word_spacing); $char_spacing = $style->length_in_pt($style->letter_spacing); switch ($style->white_space) { default: case "normal": $str = preg_replace(self::$_whitespace_pattern, " ", $str); case "pre-wrap": case "pre-line": // Find the longest word (i.e. minimum length) // This technique (using arrays & an anonymous function) is actually // faster than doing a single-pass character by character scan. Heh, // yes I took the time to bench it ;) $words = array_flip(preg_split("/[\\s-]+/u", $str, -1, PREG_SPLIT_DELIM_CAPTURE)); array_walk($words, create_function('&$val,$str', '$val = Font_Metrics::get_text_width($str, "' . addslashes($font) . '", ' . $size . ', ' . $word_spacing . ', ' . $char_spacing . ');')); arsort($words); $min = reset($words); break; case "pre": $lines = array_flip(preg_split("/\n/u", $str)); array_walk($lines, create_function('&$val,$str', '$val = Font_Metrics::get_text_width($str, "' . addslashes($font) . '", ' . $size . ', ' . $word_spacing . ', ' . $char_spacing . ');')); arsort($lines); $min = reset($lines); break; case "nowrap": $min = Font_Metrics::get_text_width($this->_collapse_white_space($str), $font, $size, $word_spacing, $char_spacing); break; } switch ($style->white_space) { default: case "normal": case "nowrap": $str = preg_replace(self::$_whitespace_pattern, " ", $text); break; case "pre-line": //XXX: Is this correct? $str = preg_replace("/[ \t]+/u", " ", $text); case "pre-wrap": // Find the longest word (i.e. minimum length) $lines = array_flip(preg_split("/\n/", $text)); array_walk($lines, create_function('&$val,$str', '$val = Font_Metrics::get_text_width($str, "' . $font . '", ' . $size . ', ' . $word_spacing . ', ' . $char_spacing . ');')); arsort($lines); reset($lines); $str = key($lines); break; } $max = Font_Metrics::get_text_width($str, $font, $size, $word_spacing, $char_spacing); $delta = $style->length_in_pt(array($style->margin_left, $style->border_left_width, $style->padding_left, $style->padding_right, $style->border_right_width, $style->margin_right), $line_width); $min += $delta; $max += $delta; return array($min, $max, "min" => $min, "max" => $max); }