Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// $Header: /cvsroot/html2ps/utils_array.php,v 1.7 2006/09/07 18:38:16 Konstantin Exp $
3
 
4
function any_flag_set(&$flags) {
5
  for ($i=0, $size = count($flags); $i<$size; $i++) {
6
    if ($flags[$i]) { return true; };
7
  }
8
  return false;
9
}
10
 
11
function expand_to_with_flags($size, $array, $flags) {
12
  // if array have no elements - return immediately
13
  if (count($array) == 0) { return $array; };
14
 
15
  // Never decrease exising values
16
  if (array_sum($array) > $size) {
17
    return $array;
18
  }
19
 
20
  // Subtract non-modifiable values from target value
21
  for ($i=0; $i < count($array); $i++) {
22
    if (!$flags[$i]) { $size -= $array[$i]; };
23
  };
24
 
25
  // Check if there's any expandable columns
26
  $sum = 0;
27
  for ($i=0, $count = count($flags); $i<$count; $i++) {
28
    if ($flags[$i]) { $sum += $array[$i]; };
29
  }
30
 
31
  if ($sum == 0) {
32
    // Note that this function is used in colpans-width calculation routine
33
    // If we executing this branch, then we've got a colspan over non-resizable columns
34
    // So, we decide to expand the very first column; note that 'Size' in this case
35
    // will contain the delta value for the width and we need to _add_ it to the first
36
    // column's width
37
    $array[0] += $size;
38
    return $array;
39
  }
40
 
41
  // Calculate scale koeff
42
  $koeff = $size / $sum;
43
 
44
  // Apply scale koeff
45
  for ($i=0, $count = count($flags); $i < $count; $i++) {
46
    if ($flags[$i]) { $array[$i] *= $koeff; };
47
  }
48
 
49
  return $array;
50
}
51
 
52
function expand_to($size, $array) {
53
  // if array have no elements - return immediately
54
  if (count($array) == 0) { return $array; };
55
 
56
  // If array contains only zero elements (or no elements at all) do not do anything
57
  if (array_sum($array) == 0) { return $array; };
58
 
59
  // Never decrease exising values
60
  if (array_sum($array) > $size) {
61
    return $array;
62
  }
63
 
64
  // Calculate scale koeff
65
  $koeff = $size / array_sum($array);
66
 
67
  // Apply scale koeff
68
  for ($i=0, $size = count($array); $i<$size; $i++) {
69
    $array[$i] *= $koeff;
70
  }
71
 
72
  return $array;
73
}
74
?>