[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libs/fpdf/ -> chinese.php (source)

   1  <?php
   2  require(dirname(__FILE__) . '/fpdf.php');
   3  
   4  class PDF_Chinese extends FPDF
   5  {
   6      var $Big5_widths = array();
   7      var $GB_widths = array();
   8      function PDF_Chinese($orientation = 'P', $unit = 'mm', $format = 'A4')
   9      {
  10          FPDF::FPDF($orientation = 'P', $unit = 'mm', $format = 'A4');
  11          $this->Big5_widths = array(' ' => 250, '!' => 250, '"' => 408, '#' => 668, '$' => 490, '%' => 875, '&' => 698, '\'' => 250,
  12              '(' => 240, ')' => 240, '*' => 417, '+' => 667, ',' => 250, '-' => 313, '.' => 250, '/' => 520, '0' => 500, '1' => 500,
  13              '2' => 500, '3' => 500, '4' => 500, '5' => 500, '6' => 500, '7' => 500, '8' => 500, '9' => 500, ':' => 250, ';' => 250,
  14              '<' => 667, '=' => 667, '>' => 667, '?' => 396, '@' => 921, 'A' => 677, 'B' => 615, 'C' => 719, 'D' => 760, 'E' => 625,
  15              'F' => 552, 'G' => 771, 'H' => 802, 'I' => 354, 'J' => 354, 'K' => 781, 'L' => 604, 'M' => 927, 'N' => 750, 'O' => 823,
  16              'P' => 563, 'Q' => 823, 'R' => 729, 'S' => 542, 'T' => 698, 'U' => 771, 'V' => 729, 'W' => 948, 'X' => 771, 'Y' => 677,
  17              'Z' => 635, '[' => 344, '\\' => 520, ']' => 344, '^' => 469, '_' => 500, '`' => 250, 'a' => 469, 'b' => 521, 'c' => 427,
  18              'd' => 521, 'e' => 438, 'f' => 271, 'g' => 469, 'h' => 531, 'i' => 250, 'j' => 250, 'k' => 458, 'l' => 240, 'm' => 802,
  19              'n' => 531, 'o' => 500, 'p' => 521, 'q' => 521, 'r' => 365, 's' => 333, 't' => 292, 'u' => 521, 'v' => 458, 'w' => 677,
  20              'x' => 479, 'y' => 458, 'z' => 427, '{' => 480, '|' => 496, '}' => 480, '~' => 667);
  21  
  22          $this->GB_widths = array(' ' => 207, '!' => 270, '"' => 342, '#' => 467, '$' => 462, '%' => 797, '&' => 710, '\'' => 239,
  23              '(' => 374, ')' => 374, '*' => 423, '+' => 605, ',' => 238, '-' => 375, '.' => 238, '/' => 334, '0' => 462, '1' => 462,
  24              '2' => 462, '3' => 462, '4' => 462, '5' => 462, '6' => 462, '7' => 462, '8' => 462, '9' => 462, ':' => 238, ';' => 238,
  25              '<' => 605, '=' => 605, '>' => 605, '?' => 344, '@' => 748, 'A' => 684, 'B' => 560, 'C' => 695, 'D' => 739, 'E' => 563,
  26              'F' => 511, 'G' => 729, 'H' => 793, 'I' => 318, 'J' => 312, 'K' => 666, 'L' => 526, 'M' => 896, 'N' => 758, 'O' => 772,
  27              'P' => 544, 'Q' => 772, 'R' => 628, 'S' => 465, 'T' => 607, 'U' => 753, 'V' => 711, 'W' => 972, 'X' => 647, 'Y' => 620,
  28              'Z' => 607, '[' => 374, '\\' => 333, ']' => 374, '^' => 606, '_' => 500, '`' => 239, 'a' => 417, 'b' => 503, 'c' => 427,
  29              'd' => 529, 'e' => 415, 'f' => 264, 'g' => 444, 'h' => 518, 'i' => 241, 'j' => 230, 'k' => 495, 'l' => 228, 'm' => 793,
  30              'n' => 527, 'o' => 524, 'p' => 524, 'q' => 504, 'r' => 338, 's' => 336, 't' => 277, 'u' => 517, 'v' => 450, 'w' => 652,
  31              'x' => 466, 'y' => 452, 'z' => 407, '{' => 370, '|' => 258, '}' => 370, '~' => 605);
  32      } 
  33      function AddCIDFont($family, $style, $name, $cw, $CMap, $registry)
  34      {
  35          $fontkey = strtolower($family) . strtoupper($style);
  36          if (isset($this->fonts[$fontkey]))
  37              $this->Error("Font already added: $family $style");
  38          $i = count($this->fonts) + 1;
  39          $name = str_replace(' ', '', $name);
  40          $this->fonts[$fontkey] = array('i' => $i, 'type' => 'Type0', 'name' => $name, 'up' => -130, 'ut' => 40, 'cw' => $cw, 'CMap' => $CMap, 'registry' => $registry);
  41      } 
  42  
  43      function AddCIDFonts($family, $name, $cw, $CMap, $registry)
  44      {
  45          $this->AddCIDFont($family, '', $name, $cw, $CMap, $registry);
  46          $this->AddCIDFont($family, 'B', $name . ',Bold', $cw, $CMap, $registry);
  47          $this->AddCIDFont($family, 'I', $name . ',Italic', $cw, $CMap, $registry);
  48          $this->AddCIDFont($family, 'BI', $name . ',BoldItalic', $cw, $CMap, $registry);
  49      } 
  50  
  51      function AddBig5Font($family = 'Big5', $name = 'MSungStd-Light-Acro')
  52      { 
  53          // Add Big5 font with proportional Latin

  54          $cw = $this->Big5_widths;
  55          $CMap = 'ETenms-B5-H';
  56          $registry = array('ordering' => 'CNS1', 'supplement' => 0);
  57          $this->AddCIDFonts($family, $name, $cw, $CMap, $registry);
  58      } 
  59  
  60      function AddBig5hwFont($family = 'Big5-hw', $name = 'MSungStd-Light-Acro')
  61      { 
  62          // Add Big5 font with half-witdh Latin

  63          for($i = 32;$i <= 126;$i++)
  64          $cw[chr($i)] = 500;
  65          $CMap = 'ETen-B5-H';
  66          $registry = array('ordering' => 'CNS1', 'supplement' => 0);
  67          $this->AddCIDFonts($family, $name, $cw, $CMap, $registry);
  68      } 
  69  
  70      function AddGBFont($family = 'GB', $name = 'STSongStd-Light-Acro')
  71      { 
  72          // Add GB font with proportional Latin

  73          $cw = $this->GB_widths;
  74          $CMap = 'GBKp-EUC-H';
  75          $registry = array('ordering' => 'GB1', 'supplement' => 2);
  76          $this->AddCIDFonts($family, $name, $cw, $CMap, $registry);
  77      } 
  78  
  79      function AddGBhwFont($family = 'GB-hw', $name = 'STSongStd-Light-Acro')
  80      { 
  81          // Add GB font with half-width Latin

  82          for($i = 32;$i <= 126;$i++)
  83          $cw[chr($i)] = 500;
  84          $CMap = 'GBK-EUC-H';
  85          $registry = array('ordering' => 'GB1', 'supplement' => 2);
  86          $this->AddCIDFonts($family, $name, $cw, $CMap, $registry);
  87      } 
  88  
  89      function GetStringWidth($s)
  90      {
  91          if ($this->CurrentFont['type'] == 'Type0')
  92              return $this->GetMBStringWidth($s);
  93          else
  94              return parent::GetStringWidth($s);
  95      } 
  96  
  97      function GetMBStringWidth($s)
  98      { 
  99          // Multi-byte version of GetStringWidth()

 100          $l = 0;
 101          $cw = &$this->CurrentFont['cw'];
 102          $nb = strlen($s);
 103          $i = 0;
 104          while ($i < $nb)
 105          {
 106              $c = $s[$i];
 107              if (ord($c) < 128)
 108              {
 109                  $l += $cw[$c];
 110                  $i++;
 111              } 
 112              else
 113              {
 114                  $l += 1000;
 115                  $i += 2;
 116              } 
 117          } 
 118          return $l * $this->FontSize / 1000;
 119      } 
 120  
 121      function MultiCell($w, $h, $txt, $border = 0, $align = 'L', $fill = 0)
 122      {
 123          if ($this->CurrentFont['type'] == 'Type0')
 124              $this->MBMultiCell($w, $h, $txt, $border, $align, $fill);
 125          else
 126              parent::MultiCell($w, $h, $txt, $border, $align, $fill);
 127      } 
 128  
 129      function MBMultiCell($w, $h, $txt, $border = 0, $align = 'L', $fill = 0)
 130      { 
 131          // Multi-byte version of MultiCell()

 132          $cw = &$this->CurrentFont['cw'];
 133          if ($w == 0)
 134              $w = $this->w - $this->rMargin - $this->x;
 135          $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
 136          $s = str_replace("\r", '', $txt);
 137          $nb = strlen($s);
 138          if ($nb > 0 and $s[$nb-1] == "\n")
 139              $nb--;
 140          $b = 0;
 141          if ($border)
 142          {
 143              if ($border == 1)
 144              {
 145                  $border = 'LTRB';
 146                  $b = 'LRT';
 147                  $b2 = 'LR';
 148              } 
 149              else
 150              {
 151                  $b2 = '';
 152                  if (is_int(strpos($border, 'L')))
 153                      $b2 .= 'L';
 154                  if (is_int(strpos($border, 'R')))
 155                      $b2 .= 'R';
 156                  $b = is_int(strpos($border, 'T')) ? $b2 . 'T' : $b2;
 157              } 
 158          } 
 159          $sep = -1;
 160          $i = 0;
 161          $j = 0;
 162          $l = 0;
 163          $nl = 1;
 164          while ($i < $nb)
 165          { 
 166              // Get next character

 167              $c = $s[$i]; 
 168              // Check if ASCII or MB

 169              $ascii = (ord($c) < 128);
 170              if ($c == "\n")
 171              { 
 172                  // Explicit line break

 173                  $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill);
 174                  $i++;
 175                  $sep = -1;
 176                  $j = $i;
 177                  $l = 0;
 178                  $nl++;
 179                  if ($border and $nl == 2)
 180                      $b = $b2;
 181                  continue;
 182              } 
 183              if (!$ascii)
 184              {
 185                  $sep = $i;
 186                  $ls = $l;
 187              } elseif ($c == ' ')
 188              {
 189                  $sep = $i;
 190                  $ls = $l;
 191              } 
 192              $l += $ascii ? $cw[$c] : 1000;
 193              if ($l > $wmax)
 194              { 
 195                  // Automatic line break

 196                  if ($sep == -1 or $i == $j)
 197                  {
 198                      if ($i == $j)
 199                          $i += $ascii ? 1 : 2;
 200                      $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill);
 201                  } 
 202                  else
 203                  {
 204                      $this->Cell($w, $h, substr($s, $j, $sep - $j), $b, 2, $align, $fill);
 205                      $i = ($s[$sep] == ' ') ? $sep + 1 : $sep;
 206                  } 
 207                  $sep = -1;
 208                  $j = $i;
 209                  $l = 0;
 210                  $nl++;
 211                  if ($border and $nl == 2)
 212                      $b = $b2;
 213              } 
 214              else
 215                  $i += $ascii ? 1 : 2;
 216          } 
 217          // Last chunk

 218          if ($border and is_int(strpos($border, 'B')))
 219              $b .= 'B';
 220          $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill);
 221          $this->x = $this->lMargin;
 222      } 
 223  
 224      function Write($h, $txt, $link = '')
 225      {
 226          if ($this->CurrentFont['type'] == 'Type0')
 227              $this->MBWrite($h, $txt, $link);
 228          else
 229              parent::Write($h, $txt, $link);
 230      } 
 231  
 232      function MBWrite($h, $txt, $link)
 233      { 
 234          // Multi-byte version of Write()

 235          $cw = &$this->CurrentFont['cw'];
 236          $w = $this->w - $this->rMargin - $this->x;
 237          $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
 238          $s = str_replace("\r", '', $txt);
 239          $nb = strlen($s);
 240          $sep = -1;
 241          $i = 0;
 242          $j = 0;
 243          $l = 0;
 244          $nl = 1;
 245          while ($i < $nb)
 246          { 
 247              // Get next character

 248              $c = $s[$i]; 
 249              // Check if ASCII or MB

 250              $ascii = (ord($c) < 128);
 251              if ($c == "\n")
 252              { 
 253                  // Explicit line break

 254                  $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link);
 255                  $i++;
 256                  $sep = -1;
 257                  $j = $i;
 258                  $l = 0;
 259                  if ($nl == 1)
 260                  {
 261                      $this->x = $this->lMargin;
 262                      $w = $this->w - $this->rMargin - $this->x;
 263                      $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
 264                  } 
 265                  $nl++;
 266                  continue;
 267              } 
 268              if (!$ascii or $c == ' ')
 269                  $sep = $i;
 270              $l += $ascii ? $cw[$c] : 1000;
 271              if ($l > $wmax)
 272              { 
 273                  // Automatic line break

 274                  if ($sep == -1 or $i == $j)
 275                  {
 276                      if ($this->x > $this->lMargin)
 277                      { 
 278                          // Move to next line

 279                          $this->x = $this->lMargin;
 280                          $this->y += $h;
 281                          $w = $this->w - $this->rMargin - $this->x;
 282                          $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
 283                          $i++;
 284                          $nl++;
 285                          continue;
 286                      } 
 287                      if ($i == $j)
 288                          $i += $ascii ? 1 : 2;
 289                      $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link);
 290                  } 
 291                  else
 292                  {
 293                      $this->Cell($w, $h, substr($s, $j, $sep - $j), 0, 2, '', 0, $link);
 294                      $i = ($s[$sep] == ' ') ? $sep + 1 : $sep;
 295                  } 
 296                  $sep = -1;
 297                  $j = $i;
 298                  $l = 0;
 299                  if ($nl == 1)
 300                  {
 301                      $this->x = $this->lMargin;
 302                      $w = $this->w - $this->rMargin - $this->x;
 303                      $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
 304                  } 
 305                  $nl++;
 306              } 
 307              else
 308                  $i += $ascii ? 1 : 2;
 309          } 
 310          // Last chunk

 311          if ($i != $j)
 312              $this->Cell($l / 1000 * $this->FontSize, $h, substr($s, $j, $i - $j), 0, 0, '', 0, $link);
 313      } 
 314  
 315      function _putfonts()
 316      {
 317          $nf = $this->n;
 318          foreach($this->diffs as $diff)
 319          { 
 320              // Encodings

 321              $this->_newobj();
 322              $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $diff . ']>>');
 323              $this->_out('endobj');
 324          } 
 325          $mqr = get_magic_quotes_runtime();
 326          set_magic_quotes_runtime(0);
 327          foreach($this->FontFiles as $file => $info)
 328          { 
 329              // Font file embedding

 330              $this->_newobj();
 331              $this->FontFiles[$file]['n'] = $this->n;
 332              if (defined('FPDF_FONTPATH'))
 333                  $file = FPDF_FONTPATH . $file;
 334              $size = filesize($file);
 335              if (!$size)
 336                  $this->Error('Font file not found');
 337              $this->_out('<</Length ' . $size);
 338              if (substr($file, -2) == '.z')
 339                  $this->_out('/Filter /FlateDecode');
 340              $this->_out('/Length1 ' . $info['length1']);
 341              if (isset($info['length2']))
 342                  $this->_out('/Length2 ' . $info['length2'] . ' /Length3 0');
 343              $this->_out('>>');
 344              $f = fopen($file, 'rb');
 345              $this->_putstream(fread($f, $size));
 346              fclose($f);
 347              $this->_out('endobj');
 348          } 
 349          set_magic_quotes_runtime($mqr);
 350          foreach($this->fonts as $k => $font)
 351          { 
 352              // Font objects

 353              $this->_newobj();
 354              $this->fonts[$k]['n'] = $this->n;
 355              $this->_out('<</Type /Font');
 356              if ($font['type'] == 'Type0')
 357                  $this->_putType0($font);
 358              else
 359              {
 360                  $name = $font['name'];
 361                  $this->_out('/BaseFont /' . $name);
 362                  if ($font['type'] == 'core')
 363                  { 
 364                      // Standard font

 365                      $this->_out('/Subtype /Type1');
 366                      if ($name != 'Symbol' and $name != 'ZapfDingbats')
 367                          $this->_out('/Encoding /WinAnsiEncoding');
 368                  } 
 369                  else
 370                  { 
 371                      // Additional font

 372                      $this->_out('/Subtype /' . $font['type']);
 373                      $this->_out('/FirstChar 32');
 374                      $this->_out('/LastChar 255');
 375                      $this->_out('/Widths ' . ($this->n + 1) . ' 0 R');
 376                      $this->_out('/FontDescriptor ' . ($this->n + 2) . ' 0 R');
 377                      if ($font['enc'])
 378                      {
 379                          if (isset($font['diff']))
 380                              $this->_out('/Encoding ' . ($nf + $font['diff']) . ' 0 R');
 381                          else
 382                              $this->_out('/Encoding /WinAnsiEncoding');
 383                      } 
 384                  } 
 385                  $this->_out('>>');
 386                  $this->_out('endobj');
 387                  if ($font['type'] != 'core')
 388                  { 
 389                      // Widths

 390                      $this->_newobj();
 391                      $cw = &$font['cw'];
 392                      $s = '[';
 393                      for($i = 32;$i <= 255;$i++)
 394                      $s .= $cw[chr($i)] . ' ';
 395                      $this->_out($s . ']');
 396                      $this->_out('endobj'); 
 397                      // Descriptor

 398                      $this->_newobj();
 399                      $s = '<</Type /FontDescriptor /FontName /' . $name;
 400                      foreach($font['desc'] as $k => $v)
 401                      $s .= ' /' . $k . ' ' . $v;
 402                      $file = $font['file'];
 403                      if ($file)
 404                          $s .= ' /FontFile' . ($font['type'] == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$file]['n'] . ' 0 R';
 405                      $this->_out($s . '>>');
 406                      $this->_out('endobj');
 407                  } 
 408              } 
 409          } 
 410      } 
 411  
 412      function _putType0($font)
 413      { 
 414          // Type0

 415          $this->_out('/Subtype /Type0');
 416          $this->_out('/BaseFont /' . $font['name'] . '-' . $font['CMap']);
 417          $this->_out('/Encoding /' . $font['CMap']);
 418          $this->_out('/DescendantFonts [' . ($this->n + 1) . ' 0 R]');
 419          $this->_out('>>');
 420          $this->_out('endobj'); 
 421          // CIDFont

 422          $this->_newobj();
 423          $this->_out('<</Type /Font');
 424          $this->_out('/Subtype /CIDFontType0');
 425          $this->_out('/BaseFont /' . $font['name']);
 426          $this->_out('/CIDSystemInfo <</Registry (Adobe) /Ordering (' . $font['registry']['ordering'] . ') /Supplement ' . $font['registry']['supplement'] . '>>');
 427          $this->_out('/FontDescriptor ' . ($this->n + 1) . ' 0 R');
 428          if ($font['CMap'] == 'ETen-B5-H')
 429              $W = '13648 13742 500';
 430          elseif ($font['CMap'] == 'GBK-EUC-H')
 431              $W = '814 907 500 7716 [500]';
 432          else
 433              $W = '1 [' . implode(' ', $font['cw']) . ']';
 434          $this->_out('/W [' . $W . ']>>');
 435          $this->_out('endobj'); 
 436          // Font descriptor

 437          $this->_newobj();
 438          $this->_out('<</Type /FontDescriptor');
 439          $this->_out('/FontName /' . $font['name']);
 440          $this->_out('/Flags 6');
 441          $this->_out('/FontBBox [0 -200 1000 900]');
 442          $this->_out('/ItalicAngle 0');
 443          $this->_out('/Ascent 800');
 444          $this->_out('/Descent -200');
 445          $this->_out('/CapHeight 800');
 446          $this->_out('/StemV 50');
 447          $this->_out('>>');
 448          $this->_out('endobj');
 449      } 
 450  } 
 451  
 452  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics