1<?php 2// $Header: /cvsroot/html2ps/tag.frame.inc.php,v 1.19 2006/05/27 15:33:27 Konstantin Exp $ 3 4/** 5 * Calculated the actual size of frameset rows/columns using value 6 * specified in 'rows' of 'cols' attribute. This value is defined as 7 * "MultiLength"; according to HTML 4.01 6.6: 8 * 9 * MultiLength: The value ( %MultiLength; in the DTD) may be a 10 * %Length; or a relative length. A relative length has the form "i*", 11 * where "i" is an integer. When allotting space among elements 12 * competing for that space, user agents allot pixel and percentage 13 * lengths first, then divide up remaining available space among 14 * relative lengths. Each relative length receives a portion of the 15 * available space that is proportional to the integer preceding the 16 * "*". The value "*" is equivalent to "1*". Thus, if 60 pixels of 17 * space are available after the user agent allots pixel and 18 * percentage space, and the competing relative lengths are 1*, 2*, 19 * and 3*, the 1* will be alloted 10 pixels, the 2* will be alloted 20 20 * pixels, and the 3* will be alloted 30 pixels. 21 * 22 * @param $lengths_src String source Multilength value 23 * @param $total Integer total space to be filled 24 * 25 * @return Array list of calculated lengths 26 */ 27function guess_lengths($lengths_src, $total) { 28 /** 29 * Initialization: the comma-separated list is exploded to the array 30 * of distinct values, list of calculated lengths is initialized 31 * with default (zero) values 32 */ 33 $lengths = explode(",",$lengths_src); 34 $values = array(); 35 foreach ($lengths as $length) { 36 $values[] = 0; 37 }; 38 39 /** 40 * First pass: fixed-width sizes (%Length). There's two types of 41 * fixed widths: pixel widths and percentage widths 42 * 43 * According to HTML 4.01, 6.6: 44 * 45 * Length: The value (%Length; in the DTD) may be either a %Pixel; 46 * or a percentage of the available horizontal or vertical 47 * space. Thus, the value "50%" means half of the available space. 48 * 49 * Pixels: The value (%Pixels; in the DTD) is an integer that 50 * represents the number of pixels of the canvas (screen, 51 * paper). Thus, the value "50" means fifty pixels. For normative 52 * information about the definition of a pixel, please consult 53 * [CSS1]. 54 */ 55 for($i=0; $i < count($lengths); $i++) { 56 /** 57 * Remove leading/trailing spaces from current text value 58 */ 59 $length_src = trim($lengths[$i]); 60 61 if (substr($length_src,strlen($length_src)-1,1) == "%") { 62 /** 63 * Percentage value 64 */ 65 $fraction = substr($length_src, 0, strlen($length_src)-1) / 100; 66 $values[$i] = $total * $fraction; 67 68 } elseif (substr($length_src,strlen($length_src)-1,1) != "*") { 69 /** 70 * Pixel value 71 */ 72 $values[$i] = px2pt($length_src); 73 }; 74 }; 75 76 // Second pass: relative-width columns 77 $rest = $total - array_sum($values); 78 79 $parts = 0; 80 foreach ($lengths as $length_src) { 81 if (substr($length_src,strlen($length_src)-1,1) == "*") { 82 $parts += max(1,substr($length_src,0,strlen($length)-1)); 83 }; 84 }; 85 86 if ($parts > 0) { 87 $part_size = $rest / $parts; 88 89 for ($i = 0; $i < count($lengths); $i++) { 90 $length = $lengths[$i]; 91 92 if (substr($length,strlen($length)-1,1) == "*") { 93 $values[$i] = $part_size * max(1,substr($length,0,strlen($length)-1)); 94 }; 95 }; 96 }; 97 98 // Fix over/underconstrained framesets 99 $width = array_sum($values); 100 101 if ($width > 0) { 102 $koeff = $total / $width; 103 for($i = 0; $i < count($values); $i++) { 104 $values[$i] *= $koeff; 105 }; 106 }; 107 108 return $values; 109} 110 111?>