Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 842c69c219280b393b8693c315e2704eae17e257 0 parents
Edwin Moss authored
Showing with 28,126 additions and 0 deletions.
  1. +2 −0  .gitignore
  2. +13 −0 CHANGELOG
  3. +20 −0 MIT-LICENSE
  4. +43 −0 README
  5. +19 −0 environment.rb
  6. +9 −0 init.rb
  7. 0  install.rb
  8. +448 −0 lib/barcode/barcode.rb
  9. +393 −0 lib/barcode/c128aobject.rb
  10. +393 −0 lib/barcode/c128bobject.rb
  11. +414 −0 lib/barcode/c128cobject.rb
  12. +281 −0 lib/barcode/c39object.rb
  13. +216 −0 lib/barcode/i25object.rb
  14. +87 −0 lib/barcode/image.rb
  15. +504 −0 lib/barcode/lesser.txt
  16. +48 −0 lib/config/lang/eng.rb
  17. +282 −0 lib/core/rfpdf.rb
  18. +75 −0 lib/core/view.rb
  19. 0  lib/fonts/.noencode
  20. BIN  lib/fonts/FreeMono.ctg.z
  21. BIN  lib/fonts/FreeMono.z
  22. BIN  lib/fonts/FreeMonoBold.ctg.z
  23. BIN  lib/fonts/FreeMonoBold.z
  24. BIN  lib/fonts/FreeMonoBoldOblique.ctg.z
  25. BIN  lib/fonts/FreeMonoBoldOblique.z
  26. BIN  lib/fonts/FreeMonoOblique.ctg.z
  27. BIN  lib/fonts/FreeMonoOblique.z
  28. BIN  lib/fonts/FreeSans.ctg.z
  29. BIN  lib/fonts/FreeSans.z
  30. BIN  lib/fonts/FreeSansBold.ctg.z
  31. BIN  lib/fonts/FreeSansBold.z
  32. BIN  lib/fonts/FreeSansBoldOblique.ctg.z
  33. BIN  lib/fonts/FreeSansBoldOblique.z
  34. BIN  lib/fonts/FreeSansOblique.ctg.z
  35. BIN  lib/fonts/FreeSansOblique.z
  36. +2 −0  lib/fonts/README.z
  37. +25 −0 lib/fonts/courier.rb
  38. +38 −0 lib/fonts/dejavu-ttf-2.15/AUTHORS
  39. +3 −0  lib/fonts/dejavu-ttf-2.15/BUGS
  40. +98 −0 lib/fonts/dejavu-ttf-2.15/LICENSE
  41. +789 −0 lib/fonts/dejavu-ttf-2.15/NEWS
  42. +59 −0 lib/fonts/dejavu-ttf-2.15/README
  43. +187 −0 lib/fonts/dejavu-ttf-2.15/langcover.txt
  44. +4,641 −0 lib/fonts/dejavu-ttf-2.15/status.txt
  45. +160 −0 lib/fonts/dejavu-ttf-2.15/unicover.txt
  46. +143 −0 lib/fonts/freefont/AUTHORS
  47. +389 −0 lib/fonts/freefont/CREDITS
  48. +630 −0 lib/fonts/freefont/ChangeLog
  49. +57 −0 lib/fonts/freefont/INSTALL
  50. +113 −0 lib/fonts/freefont/README
  51. +174 −0 lib/fonts/freemono.rb
  52. +107 −0 lib/fonts/freemonob.rb
  53. +62 −0 lib/fonts/freemonobi.rb
  54. +89 −0 lib/fonts/freemonoi.rb
  55. +149 −0 lib/fonts/freesans.rb
  56. +79 −0 lib/fonts/freesansb.rb
  57. +76 −0 lib/fonts/freesansbi.rb
  58. +85 −0 lib/fonts/freesansi.rb
  59. +4 −0 lib/fonts/helvetica.rb
  60. +15 −0 lib/fonts/helveticab.rb
  61. +15 −0 lib/fonts/helveticabi.rb
  62. +15 −0 lib/fonts/helveticai.rb
  63. 0  lib/fonts/old/.noencode
  64. +251 −0 lib/fonts/old/makefont/cp1250.map
  65. +255 −0 lib/fonts/old/makefont/cp1251.map
  66. +251 −0 lib/fonts/old/makefont/cp1252.map
  67. +239 −0 lib/fonts/old/makefont/cp1253.map
  68. +249 −0 lib/fonts/old/makefont/cp1254.map
  69. +233 −0 lib/fonts/old/makefont/cp1255.map
  70. +244 −0 lib/fonts/old/makefont/cp1257.map
  71. +247 −0 lib/fonts/old/makefont/cp1258.map
  72. +225 −0 lib/fonts/old/makefont/cp874.map
  73. +256 −0 lib/fonts/old/makefont/iso-8859-1.map
  74. +248 −0 lib/fonts/old/makefont/iso-8859-11.map
  75. +256 −0 lib/fonts/old/makefont/iso-8859-15.map
  76. +256 −0 lib/fonts/old/makefont/iso-8859-16.map
  77. +256 −0 lib/fonts/old/makefont/iso-8859-2.map
  78. +256 −0 lib/fonts/old/makefont/iso-8859-4.map
  79. +256 −0 lib/fonts/old/makefont/iso-8859-5.map
  80. +250 −0 lib/fonts/old/makefont/iso-8859-7.map
  81. +256 −0 lib/fonts/old/makefont/iso-8859-9.map
  82. +256 −0 lib/fonts/old/makefont/koi8-r.map
  83. +256 −0 lib/fonts/old/makefont/koi8-u.map
  84. +411 −0 lib/fonts/old/makefont/makefont.php
  85. +834 −0 lib/fonts/sjis.rb
  86. +15 −0 lib/fonts/symbol.rb
  87. +15 −0 lib/fonts/times.rb
  88. +15 −0 lib/fonts/timesb.rb
  89. +15 −0 lib/fonts/timesbi.rb
  90. +15 −0 lib/fonts/timesi.rb
  91. +124 −0 lib/fonts/ttf-bitstream-vera-1.10/COPYRIGHT.TXT
  92. +11 −0 lib/fonts/ttf-bitstream-vera-1.10/README.TXT
  93. +162 −0 lib/fonts/ttf-bitstream-vera-1.10/RELEASENOTES.TXT
  94. +32 −0 lib/fonts/ttf-bitstream-vera-1.10/local.conf
  95. +25 −0 lib/fonts/ttf2ufm/README.TXT
  96. +314 −0 lib/fonts/ttf2ufm/makefontuni.php
  97. +313 −0 lib/fonts/ttf2ufm/makefontuni.rb
  98. BIN  lib/fonts/ttf2ufm/ttf2ufm.exe
  99. BIN  lib/fonts/vera.ctg.z
  100. +30 −0 lib/fonts/vera.rb
  101. BIN  lib/fonts/vera.z
  102. BIN  lib/fonts/verab.ctg.z
  103. +30 −0 lib/fonts/verab.rb
  104. BIN  lib/fonts/verab.z
  105. BIN  lib/fonts/verabi.ctg.z
  106. +30 −0 lib/fonts/verabi.rb
  107. BIN  lib/fonts/verabi.z
  108. BIN  lib/fonts/verai.ctg.z
  109. +30 −0 lib/fonts/verai.rb
  110. BIN  lib/fonts/verai.z
  111. BIN  lib/fonts/veramo.ctg.z
  112. +30 −0 lib/fonts/veramo.rb
  113. BIN  lib/fonts/veramo.z
  114. BIN  lib/fonts/veramob.ctg.z
  115. +30 −0 lib/fonts/veramob.rb
  116. BIN  lib/fonts/veramob.z
  117. BIN  lib/fonts/veramobi.ctg.z
  118. +30 −0 lib/fonts/veramobi.rb
  119. BIN  lib/fonts/veramobi.z
  120. BIN  lib/fonts/veramoi.ctg.z
  121. +30 −0 lib/fonts/veramoi.rb
  122. BIN  lib/fonts/veramoi.z
  123. BIN  lib/fonts/verase.ctg.z
  124. +30 −0 lib/fonts/verase.rb
  125. BIN  lib/fonts/verase.z
  126. BIN  lib/fonts/veraseb.ctg.z
  127. +30 −0 lib/fonts/veraseb.rb
  128. BIN  lib/fonts/veraseb.z
  129. +15 −0 lib/fonts/zapfdingbats.rb
  130. +99 −0 lib/fpdf/bookmark.rb
  131. +473 −0 lib/fpdf/chinese.rb
  132. +4 −0 lib/fpdf/errors.rb
  133. +1,630 −0 lib/fpdf/fpdf.rb
  134. +139 −0 lib/fpdf/fpdf_eps.rb
  135. +468 −0 lib/fpdf/japanese.rb
  136. +436 −0 lib/fpdf/korean.rb
  137. +1,787 −0 lib/fpdf/makefont.rb
  138. +31 −0 lib/rfpdf.rb
  139. +3,745 −0 lib/tcpdf.rb
  140. BIN  logo_example.png
  141. +1 −0  test/test_helper.rb
  142. +115 −0 test_unicode.rfpdf
  143. +135 −0 utf8test.txt
2  .gitignore
@@ -0,0 +1,2 @@
+.DS_STORE
+.DS_Store
13 CHANGELOG
@@ -0,0 +1,13 @@
+1.00 Added view template functionality
+1.10 Added Chinese support
+1.11 Added Japanese support
+1.12 Added Korean support
+1.13 Updated to fpdf.rb 1.53d.
+ Added makefont and fpdf_eps.
+ Handle \n at the beginning of a string in MultiCell.
+ Tried to fix clipping issue in MultiCell - still needs some work.
+1.14 2006-09-26
+* Added support for @options_for_rfpdf hash for configuration:
+ * Added :filename option in this hash
+If you're using the same settings for @options_for_rfpdf often, you might want to
+put your assignment in a before_filter (perhaps overriding :filename, etc in your actions).
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2006 4ssoM LLC <www.4ssoM.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
+NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 README
@@ -0,0 +1,43 @@
+= RFPDF Template Plugin
+
+A template plugin allowing the inclusion of ERB-enabled RFPDF template files.
+
+==
+==
+== TCPDF Version (The New or UTF8 Version)
+==
+==
+
+If you are using HTML, it is recommended you install:
+
+gem install -r htmlentities
+
+TCPDF Documentation located at:
+
+http://phpdocs.moodle.org/com-tecnick-tcpdf/TCPDF.html
+
+Example of simple use in .rhtml:
+
+<%
+ @pdf = TCPDF.new()
+ @pdf.SetMargins(15, 27, 15);
+ @pdf.AddPage();
+ text_options = {:font => "freeserif"}
+ @pdf.draw_text(15, 10, "text", {:font_size => 12, :font => "freeserif"})
+%><%=@pdf.Output()%>
+
+See the following files for sample of useage:
+
+test_unicode.rfpdf
+utf8test.txt
+logo_example.png
+
+FPDF users can migrate to TCPDF by changing the following from:
+
+ pdf = FPDF.new
+
+to:
+
+ pdf = TCPDF.new
+
+ENJOY!
19 environment.rb
@@ -0,0 +1,19 @@
+begin
+ require('htmlentities')
+rescue LoadError
+ # This gem is not required - just nice to have.
+end
+require('cgi')
+
+require "#{File.dirname __FILE__}/lib/core/view"
+require "#{File.dirname __FILE__}/lib/core/rfpdf"
+
+require "#{File.dirname __FILE__}/lib/tcpdf"
+
+require "#{File.dirname __FILE__}/lib/fpdf/errors"
+require "#{File.dirname __FILE__}/lib/fpdf/fpdf"
+require "#{File.dirname __FILE__}/lib/fpdf/chinese"
+require "#{File.dirname __FILE__}/lib/fpdf/japanese"
+require "#{File.dirname __FILE__}/lib/fpdf/korean"
+
+ActionView::Base::register_template_handler 'rfpdf', RFPDF::View
9 init.rb
@@ -0,0 +1,9 @@
+##
+## Initialize the environment
+##
+require File.dirname(__FILE__) + '/environment'
+
+##
+## Run the install script, too, just to make sure
+##
+require File.dirname(__FILE__) + '/install'
0  install.rb
No changes.
448 lib/barcode/barcode.rb
@@ -0,0 +1,448 @@
+
+#============================================================+
+# File name : barcode.rb
+# Begin : 2002-07-31
+# Last Update : 2005-01-02
+# Author : Karim Mribti [barcode@mribti.com]
+# Version : 1.1 [0.0.8a (original code)]
+# License : GNU LGPL (Lesser General Public License) 2.1
+# http://www.gnu.org/copyleft/lesser.txt
+# Source Code : http://www.mribti.com/barcode/
+#
+# Description : Generic Barcode Render Class for PHP using
+# the GD graphics library.
+#
+# NOTE:
+# This version contains changes by Nicola Asuni:
+# - porting to Ruby
+# - code style and formatting
+# - automatic php documentation in PhpDocumentor Style
+# (www.phpdoc.org)
+# - minor bug fixing
+# - $mCharSet and $mChars variables were added here
+#============================================================+
+
+#
+# Barcode Render Class for PHP using the GD graphics library.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+
+# Styles
+# Global
+
+#
+# option: generate barcode border
+#
+define("BCS_BORDER", 1);
+
+#
+# option: use transparent background
+#
+define("BCS_TRANSPARENT", 2);
+
+#
+# option: center barcode
+#
+define("BCS_ALIGN_CENTER", 4);
+
+#
+# option: align left
+#
+define("BCS_ALIGN_LEFT", 8);
+
+#
+# option: align right
+#
+define("BCS_ALIGN_RIGHT", 16);
+
+#
+# option: generate JPEG image
+#
+define("BCS_IMAGE_JPEG", 32);
+
+#
+# option: generate PNG image
+#
+define("BCS_IMAGE_PNG", 64);
+
+#
+# option: draw text
+#
+define("BCS_DRAW_TEXT", 128);
+
+#
+# option: stretch text
+#
+define("BCS_STRETCH_TEXT", 256);
+
+#
+# option: reverse color
+#
+define("BCS_REVERSE_COLOR", 512);
+
+#
+# option: draw check
+# (only for I25 code)
+#
+define("BCS_I25_DRAW_CHECK", 2048);
+
+#
+# set default background color
+#
+define("BCD_DEFAULT_BACKGROUND_COLOR", 0xFFFFFF);
+
+#
+# set default foreground color
+#
+define("BCD_DEFAULT_FOREGROUND_COLOR", 0x000000);
+
+#
+# set default style options
+#
+define("BCD_DEFAULT_STYLE", BCS_BORDER | BCS_ALIGN_CENTER | BCS_IMAGE_PNG);
+
+#
+# set default width
+#
+define("BCD_DEFAULT_WIDTH", 460);
+
+#
+# set default height
+#
+define("BCD_DEFAULT_HEIGHT", 120);
+
+#
+# set default font
+#
+define("BCD_DEFAULT_FONT", 5);
+
+#
+# st default horizontal resolution
+#
+define("BCD_DEFAULT_XRES", 2);
+
+# Margins
+
+#
+# set default margin
+#
+define("BCD_DEFAULT_MAR_Y1", 0);
+
+#
+# set default margin
+#
+define("BCD_DEFAULT_MAR_Y2", 0);
+
+#
+# set default text offset
+#
+define("BCD_DEFAULT_TEXT_OFFSET", 2);
+
+# For the I25 Only
+
+#
+# narrow bar option
+# (only for I25 code)
+#
+define("BCD_I25_NARROW_BAR", 1);
+
+#
+# wide bar option
+# (only for I25 code)
+#
+define("BCD_I25_WIDE_BAR", 2);
+
+# For the C39 Only
+
+#
+# narrow bar option
+# (only for c39 code)
+#
+define("BCD_C39_NARROW_BAR", 1);
+
+#
+# wide bar option
+# (only for c39 code)
+#
+define("BCD_C39_WIDE_BAR", 2);
+
+# For Code 128
+
+#
+# set type 1 bar
+# (only for c128 code)
+#
+define("BCD_C128_BAR_1", 1);
+
+#
+# set type 2 bar
+# (only for c128 code)
+#
+define("BCD_C128_BAR_2", 2);
+
+#
+# set type 3 bar
+# (only for c128 code)
+#
+define("BCD_C128_BAR_3", 3);
+
+#
+# set type 4 bar
+# (only for c128 code)
+#
+define("BCD_C128_BAR_4", 4);
+
+#
+# Barcode Render Class for PHP using the GD graphics library.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+class BarcodeObject {
+ #
+ # @var Image width in pixels.
+ # @access protected
+ #
+ protected $mWidth;
+
+ #
+ # @var Image height in pixels.
+ # @access protected
+ #
+ protected $mHeight;
+
+ #
+ # @var Numeric code for Barcode style.
+ # @access protected
+ #
+ protected $mStyle;
+
+ #
+ # @var Background color.
+ # @access protected
+ #
+ protected $mBgcolor;
+
+ #
+ # @var Brush color.
+ # @access protected
+ #
+ protected $mBrush;
+
+ #
+ # @var Image object.
+ # @access protected
+ #
+ protected $mImg;
+
+ #
+ # @var Numeric code for character font.
+ # @access protected
+ #
+ protected $mFont;
+
+ #
+ # @var Error message.
+ # @access protected
+ #
+ protected $mError;
+
+ #
+ # @var Character Set.
+ # @access protected
+ #
+ protected $mCharSet;
+
+ #
+ # @var Allowed symbols.
+ # @access protected
+ #
+ protected $mChars;
+
+ #
+ # Class Constructor.
+ # @param int $Width Image width in pixels.
+ # @param int $Height Image height in pixels.
+ # @param int $Style Barcode style.
+ #
+ def __construct($Width=BCD_DEFAULT_WIDTH, $Height=BCD_DEFAULT_HEIGHT, $Style=BCD_DEFAULT_STYLE)
+ @mWidth = $Width;
+ @mHeight = $Height;
+ @mStyle = $Style;
+ @mFont = BCD_DEFAULT_FONT;
+ @mImg = ImageCreate(@mWidth, @mHeight);
+ $dbColor = @mStyle & BCS_REVERSE_COLOR ? BCD_DEFAULT_FOREGROUND_COLOR : BCD_DEFAULT_BACKGROUND_COLOR;
+ $dfColor = @mStyle & BCS_REVERSE_COLOR ? BCD_DEFAULT_BACKGROUND_COLOR : BCD_DEFAULT_FOREGROUND_COLOR;
+ @mBgcolor = ImageColorAllocate(@mImg, ($dbColor & 0xFF0000) >> 16,
+ ($dbColor & 0x00FF00) >> 8, $dbColor & 0x0000FF);
+ @mBrush = ImageColorAllocate(@mImg, ($dfColor & 0xFF0000) >> 16,
+ ($dfColor & 0x00FF00) >> 8, $dfColor & 0x0000FF);
+ if (!(@mStyle & BCS_TRANSPARENT))
+ ImageFill(@mImg, @mWidth, @mHeight, @mBgcolor);
+ end
+ end
+
+ #
+ # Class Destructor.
+ # Destroy image object.
+ #
+ def __destructor()
+ @DestroyObject();
+ end
+
+ #
+ # Returns the image object.
+ # @return object image.
+ # @author Nicola Asuni
+ # @since 1.5.2
+ #
+ def getImage()
+ return @mImg;
+ end
+
+ #
+ # Abstract method used to draw the barcode image.
+ # @param int $xres Horizontal resolution.
+ #
+ def DrawObject($xres) {
+ # there is not implementation neded, is simply the asbsract function.#
+ return false;
+ end
+
+ #
+ # Draws the barcode border.
+ # @access protected
+ #
+ protected function DrawBorder()
+ ImageRectangle(@mImg, 0, 0, @mWidth-1, @mHeight-1, @mBrush);
+ end
+
+ #
+ # Draws the alphanumeric code.
+ # @param int $Font Font type.
+ # @param int $xPos Horiziontal position.
+ # @param int $yPos Vertical position.
+ # @param int $Char Alphanumeric code to write.
+ # @access protected
+ #
+ protected function DrawChar($Font, $xPos, $yPos, $Char)
+ ImageString(@mImg,$Font,$xPos,$yPos,$Char,@mBrush);
+ end
+
+ #
+ # Draws a character string.
+ # @param int $Font Font type.
+ # @param int $xPos Horiziontal position.
+ # @param int $yPos Vertical position.
+ # @param int $Char string to write.
+ # @access protected
+ #
+ protected function DrawText($Font, $xPos, $yPos, $Char)
+ ImageString(@mImg,$Font,$xPos,$yPos,$Char,@mBrush);
+ end
+
+ #
+ # Draws a single barcode bar.
+ # @param int $xPos Horiziontal position.
+ # @param int $yPos Vertical position.
+ # @param int $xSize Horizontal size.
+ # @param int $xSize Vertical size.
+ # @return bool trur in case of success, false otherwise.
+ # @access protected
+ #
+ protected function DrawSingleBar($xPos, $yPos, $xSize, $ySize)
+ if ($xPos>=0 && $xPos<=@mWidth && ($xPos+$xSize)<=@mWidth &&
+ $yPos>=0 && $yPos<=@mHeight && ($yPos+$ySize)<=@mHeight)
+ for ($i=0;$i<$xSize;$i++)
+ ImageLine(@mImg, $xPos+$i, $yPos, $xPos+$i, $yPos+$ySize, @mBrush);
+ end
+ return true;
+ end
+ return false;
+ end
+
+ #
+ # Returns the current error message.
+ # @return string error message.
+ #
+ def GetError()
+ return @mError;
+ end
+
+ #
+ # Returns the font height.
+ # @param int $font font type.
+ # @return int font height.
+ #
+ def GetFontHeight($font)
+ return ImageFontHeight($font);
+ end
+
+ #
+ # Returns the font width.
+ # @param int $font font type.
+ # @return int font width.
+ #
+ def GetFontWidth($font)
+ return ImageFontWidth($font);
+ end
+
+ #
+ # Set font type.
+ # @param int $font font type.
+ #
+ def SetFont($font)
+ @mFont = $font;
+ end
+
+ #
+ # Returns barcode style.
+ # @return int barcode style.
+ #
+ def GetStyle()
+ return @mStyle;
+ end
+
+ #
+ # Set barcode style.
+ # @param int $Style barcode style.
+ #
+ def SetStyle ($Style)
+ @mStyle = $Style;
+ end
+
+ #
+ # Flush the barcode image.
+ #
+ def FlushObject()
+ if ((@mStyle & BCS_BORDER))
+ @DrawBorder();
+ end
+ if (@mStyle & BCS_IMAGE_PNG)
+ Header("Content-Type: image/png");
+ ImagePng(@mImg);
+ elsif (@mStyle & BCS_IMAGE_JPEG)
+ Header("Content-Type: image/jpeg");
+ ImageJpeg(@mImg);
+ end
+ end
+
+ #
+ # Destroy the barcode image.
+ #
+ def DestroyObject()
+ ImageDestroy(@mImg);
+ end
+}
+
+#============================================================+
+# END OF FILE
+#============================================================+
393 lib/barcode/c128aobject.rb
@@ -0,0 +1,393 @@
+
+#============================================================+
+# File name : c128aobject.rb
+# Begin : 2002-07-31
+# Last Update : 2004-12-29
+# Author : Karim Mribti [barcode@mribti.com]
+# Version : 0.0.8a 2001-04-01 (original code)
+# License : GNU LGPL (Lesser General Public License) 2.1
+# http://www.gnu.org/copyleft/lesser.txt
+# Source Code : http://www.mribti.com/barcode/
+#
+# Description : Code 128-A Barcode Render Class for PHP using
+# the GD graphics library.
+# Code 128-A is a continuous, multilevel and
+# include all upper case alphanumeric characters
+# and ASCII control characters.
+#
+# NOTE:
+# This version contains changes by Nicola Asuni:
+# - porting to Ruby
+# - code style and formatting
+# - automatic php documentation in PhpDocumentor Style
+# (www.phpdoc.org)
+# - minor bug fixing
+#============================================================+
+
+#
+# Code 128-A Barcode Render Class for PHP using the GD graphics library.<br>
+# Code 128-A is a continuous, multilevel and include all upper case alphanumeric characters and ASCII control characters.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+
+#
+# Code 128-A Barcode Render Class for PHP using the GD graphics library.<br>
+# Code 128-A is a continuous, multilevel and include all upper case alphanumeric characters and ASCII control characters.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+class C128AObject extends BarcodeObject {
+
+ #
+ # Class Constructor.
+ # @param int $Width Image width in pixels.
+ # @param int $Height Image height in pixels.
+ # @param int $Style Barcode style.
+ # @param int $Value value to print on barcode.
+ #
+ def __construct($Width, $Height, $Style, $Value)
+ parent::__construct($Width, $Height, $Style);
+ @mValue = $Value;
+ @mChars = " !\"#$%&'()*+�-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
+ @mCharSet = array (
+ "212222", # 00#
+ "222122", # 01#
+ "222221", # 02#
+ "121223", # 03#
+ "121322", # 04#
+ "131222", # 05#
+ "122213", # 06#
+ "122312", # 07#
+ "132212", # 08#
+ "221213", # 09#
+ "221312", # 10#
+ "231212", # 11#
+ "112232", # 12#
+ "122132", # 13#
+ "122231", # 14#
+ "113222", # 15#
+ "123122", # 16#
+ "123221", # 17#
+ "223211", # 18#
+ "221132", # 19#
+ "221231", # 20#
+ "213212", # 21#
+ "223112", # 22#
+ "312131", # 23#
+ "311222", # 24#
+ "321122", # 25#
+ "321221", # 26#
+ "312212", # 27#
+ "322112", # 28#
+ "322211", # 29#
+ "212123", # 30#
+ "212321", # 31#
+ "232121", # 32#
+ "111323", # 33#
+ "131123", # 34#
+ "131321", # 35#
+ "112313", # 36#
+ "132113", # 37#
+ "132311", # 38#
+ "211313", # 39#
+ "231113", # 40#
+ "231311", # 41#
+ "112133", # 42#
+ "112331", # 43#
+ "132131", # 44#
+ "113123", # 45#
+ "113321", # 46#
+ "133121", # 47#
+ "313121", # 48#
+ "211331", # 49#
+ "231131", # 50#
+ "213113", # 51#
+ "213311", # 52#
+ "213131", # 53#
+ "311123", # 54#
+ "311321", # 55#
+ "331121", # 56#
+ "312113", # 57#
+ "312311", # 58#
+ "332111", # 59#
+ "314111", # 60#
+ "221411", # 61#
+ "431111", # 62#
+ "111224", # 63#
+ "111422", # 64#
+ "121124", # 65#
+ "121421", # 66#
+ "141122", # 67#
+ "141221", # 68#
+ "112214", # 69#
+ "112412", # 70#
+ "122114", # 71#
+ "122411", # 72#
+ "142112", # 73#
+ "142211", # 74#
+ "241211", # 75#
+ "221114", # 76#
+ "413111", # 77#
+ "241112", # 78#
+ "134111", # 79#
+ "111242", # 80#
+ "121142", # 81#
+ "121241", # 82#
+ "114212", # 83#
+ "124112", # 84#
+ "124211", # 85#
+ "411212", # 86#
+ "421112", # 87#
+ "421211", # 88#
+ "212141", # 89#
+ "214121", # 90#
+ "412121", # 91#
+ "111143", # 92#
+ "111341", # 93#
+ "131141", # 94#
+ "114113", # 95#
+ "114311", # 96#
+ "411113", # 97#
+ "411311", # 98#
+ "113141", # 99#
+ "114131", # 100#
+ "311141", # 101#
+ "411131" # 102#
+ );
+ end
+
+ #
+ # Returns the character index.
+ # @param char $char character.
+ # @return int character index or -1 in case of error.
+ # @access private
+ #
+ def GetCharIndex($char)
+ for ($i=0;$i<64;$i++)
+ if (@mChars[$i] == $char)
+ return $i;
+ end
+ end
+ return -1;
+ end
+
+ #
+ # Returns the bar size.
+ # @param int $xres Horizontal resolution.
+ # @param char $char Character.
+ # @return int barcode size.
+ # @access private
+ #
+ def GetBarSize($xres, $char)
+ switch ($char)
+ case '1'
+ $cVal = BCD_C128_BAR_1;
+
+ case '2'
+ $cVal = BCD_C128_BAR_2;
+
+ case '3'
+ $cVal = BCD_C128_BAR_3;
+
+ case '4'
+ $cVal = BCD_C128_BAR_4;
+
+ default
+ $cVal = 0;
+ end
+ end
+ return $cVal# $xres;
+ end
+
+ #
+ # Returns barcode size.
+ # @param int $xres Horizontal resolution.
+ # @return barcode size.
+ # @access private
+ #
+ def GetSize($xres)
+ $len = @mValue.length;
+
+ if ($len == 0) {
+ @mError = "Null value";
+ return false;
+ end
+ $ret = 0;
+ for ($i=0;$i<$len;$i++)
+ if (($id = GetCharIndex(@mValue[$i])) == -1)
+ @mError = "C128A not include the char '".@mValue[$i]."'";
+ return false;
+ else
+ $cset = @mCharSet[$id];
+ $ret += GetBarSize($xres, $cset[0]);
+ $ret += GetBarSize($xres, $cset[1]);
+ $ret += GetBarSize($xres, $cset[2]);
+ $ret += GetBarSize($xres, $cset[3]);
+ $ret += GetBarSize($xres, $cset[4]);
+ $ret += GetBarSize($xres, $cset[5]);
+ end
+ end
+
+ # length of Check character#
+ $cset = GetCheckCharValue();
+ $CheckSize = 0;
+ for ($i=0;$i<6;$i++)
+ $CheckSize += GetBarSize($cset[$i], $xres);
+ end
+ $StartSize = 2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + BCD_C128_BAR_4*$xres;
+ $StopSize = 2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + 2*BCD_C128_BAR_3*$xres;
+ return $StartSize + $ret + $CheckSize + $StopSize;
+ end
+
+ #
+ # Returns the check-char value.
+ # @return string.
+ # @access private
+ #
+ def GetCheckCharValue()
+ $len = @mValue.length;
+ $sum = 103; # 'A' type;
+ for ($i=0;$i<$len;$i++)
+ $sum += GetCharIndex(@mValue[$i])# ($i+1);
+ end
+ $check = $sum % 103;
+ return @mCharSet[$check];
+ end
+
+ #
+ # Draws the start code.
+ # @param int $DrawPos Drawing position.
+ # @param int $yPos Vertical position.
+ # @param int $ySize Vertical size.
+ # @param int $xres Horizontal resolution.
+ # @return int drawing position.
+ # @access private
+ #
+ def DrawStart($DrawPos, $yPos, $ySize, $xres)
+ # Start code is '211412'#
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('2', $xres) , $ySize);
+ $DrawPos += GetBarSize('2', $xres);
+ $DrawPos += GetBarSize('1', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('1', $xres) , $ySize);
+ $DrawPos += GetBarSize('1', $xres);
+ $DrawPos += GetBarSize('4', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('1', $xres) , $ySize);
+ $DrawPos += GetBarSize('1', $xres);
+ $DrawPos += GetBarSize('2', $xres);
+ return $DrawPos;
+ end
+
+ #
+ # Draws the stop code.
+ # @param int $DrawPos Drawing position.
+ # @param int $yPos Vertical position.
+ # @param int $ySize Vertical size.
+ # @param int $xres Horizontal resolution.
+ # @return int drawing position.
+ # @access private
+ #
+ def DrawStop($DrawPos, $yPos, $ySize, $xres)
+ # Stop code is '2331112'#
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('2', $xres) , $ySize);
+ $DrawPos += GetBarSize('2', $xres);
+ $DrawPos += GetBarSize('3', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('3', $xres) , $ySize);
+ $DrawPos += GetBarSize('3', $xres);
+ $DrawPos += GetBarSize('1', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('1', $xres) , $ySize);
+ $DrawPos += GetBarSize('1', $xres);
+ $DrawPos += GetBarSize('1', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('2', $xres) , $ySize);
+ $DrawPos += GetBarSize('2', $xres);
+ return $DrawPos;
+ end
+
+ #
+ # Draws the check-char code.
+ # @param int $DrawPos Drawing position.
+ # @param int $yPos Vertical position.
+ # @param int $ySize Vertical size.
+ # @param int $xres Horizontal resolution.
+ # @return int drawing position.
+ # @access private
+ #
+ def DrawCheckChar($DrawPos, $yPos, $ySize, $xres)
+ $cset = GetCheckCharValue();
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[0], $xres) , $ySize);
+ $DrawPos += GetBarSize($cset[0], $xres);
+ $DrawPos += GetBarSize($cset[1], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[2], $xres) , $ySize);
+ $DrawPos += GetBarSize($cset[2], $xres);
+ $DrawPos += GetBarSize($cset[3], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[4], $xres) , $ySize);
+ $DrawPos += GetBarSize($cset[4], $xres);
+ $DrawPos += GetBarSize($cset[5], $xres);
+ return $DrawPos;
+ end
+
+ #
+ # Draws the barcode object.
+ # @param int $xres Horizontal resolution.
+ # @return bool true in case of success.
+ #
+ def DrawObject($xres)
+ $len = @mValue.length;
+ if (($size = GetSize($xres))==0)
+ return false;
+ end
+
+ if (@mStyle & BCS_ALIGN_CENTER) $sPos = (integer)((@mWidth - $size ) / 2);
+ elsif (@mStyle & BCS_ALIGN_RIGHT) $sPos = @mWidth - $size;
+ else $sPos = 0;
+
+ # Total height of bar code -Bars only-#
+ if (@mStyle & BCS_DRAW_TEXT) $ysize = @mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2 - GetFontHeight(@mFont);
+ else $ysize = @mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2;
+
+ # Draw text#
+ if (@mStyle & BCS_DRAW_TEXT)
+ if (@mStyle & BCS_STRETCH_TEXT)
+ for ($i=0;$i<$len;$i++)
+ @DrawChar(@mFont, $sPos+(2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + BCD_C128_BAR_4*$xres)+($size/$len)*$i,
+ $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, @mValue[$i]);
+ else# Center#
+ $text_width = GetFontWidth(@mFont)# @mValue.length;
+ @DrawText(@mFont, $sPos+(($size-$text_width)/2)+(2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + BCD_C128_BAR_4*$xres),
+ $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, @mValue);
+ end
+ end
+
+ $cPos = 0;
+ $DrawPos = @DrawStart($sPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres);
+ do {
+ $c = GetCharIndex(@mValue[$cPos]);
+ $cset = @mCharSet[$c];
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[0], $xres) , $ysize);
+ $DrawPos += GetBarSize($cset[0], $xres);
+ $DrawPos += GetBarSize($cset[1], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[2], $xres) , $ysize);
+ $DrawPos += GetBarSize($cset[2], $xres);
+ $DrawPos += GetBarSize($cset[3], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[4], $xres) , $ysize);
+ $DrawPos += GetBarSize($cset[4], $xres);
+ $DrawPos += GetBarSize($cset[5], $xres);
+ $cPos += 1;
+ end while ($cPos<$len);
+ $DrawPos = @DrawCheckChar($DrawPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres);
+ $DrawPos = @DrawStop($DrawPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres);
+ return true;
+ end
+}
+
+#============================================================+
+# END OF FILE
+#============================================================+
393 lib/barcode/c128bobject.rb
@@ -0,0 +1,393 @@
+
+#============================================================+
+# File name : c128bobject.rb
+# Begin : 2002-07-31
+# Last Update : 2004-12-29
+# Author : Karim Mribti [barcode@mribti.com]
+# Version : 0.0.8a 2001-04-01 (original code)
+# License : GNU LGPL (Lesser General Public License) 2.1
+# http://www.gnu.org/copyleft/lesser.txt
+# Source Code : http://www.mribti.com/barcode/
+#
+# Description : Code 128-B Barcode Render Class for PHP using
+# the GD graphics library.
+# Code 128-B is a continuous, multilevel and full
+# ASCII code.
+#
+# NOTE:
+# This version contains changes by Nicola Asuni:
+# - porting to Ruby
+# - code style and formatting
+# - automatic php documentation in PhpDocumentor Style
+# (www.phpdoc.org)
+# - minor bug fixing
+#============================================================+
+
+#
+# Code 128-B Barcode Render Class for PHP using the GD graphics library.<br>
+# Code 128-B is a continuous, multilevel and full ASCII code.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+
+#
+# Code 128-B Barcode Render Class for PHP using the GD graphics library.<br>
+# Code 128-B is a continuous, multilevel and full ASCII code.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+class C128BObject extends BarcodeObject {
+
+ #
+ # Class Constructor.
+ # @param int $Width Image width in pixels.
+ # @param int $Height Image height in pixels.
+ # @param int $Style Barcode style.
+ # @param int $Value value to print on barcode.
+ #
+ def __construct($Width, $Height, $Style, $Value)
+ parent::__construct($Width, $Height, $Style);
+ @mValue = $Value;
+ @mChars = " !\"#$%&'()*+�-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{ }~";
+ @mCharSet = array (
+ "212222", # 00#
+ "222122", # 01#
+ "222221", # 02#
+ "121223", # 03#
+ "121322", # 04#
+ "131222", # 05#
+ "122213", # 06#
+ "122312", # 07#
+ "132212", # 08#
+ "221213", # 09#
+ "221312", # 10#
+ "231212", # 11#
+ "112232", # 12#
+ "122132", # 13#
+ "122231", # 14#
+ "113222", # 15#
+ "123122", # 16#
+ "123221", # 17#
+ "223211", # 18#
+ "221132", # 19#
+ "221231", # 20#
+ "213212", # 21#
+ "223112", # 22#
+ "312131", # 23#
+ "311222", # 24#
+ "321122", # 25#
+ "321221", # 26#
+ "312212", # 27#
+ "322112", # 28#
+ "322211", # 29#
+ "212123", # 30#
+ "212321", # 31#
+ "232121", # 32#
+ "111323", # 33#
+ "131123", # 34#
+ "131321", # 35#
+ "112313", # 36#
+ "132113", # 37#
+ "132311", # 38#
+ "211313", # 39#
+ "231113", # 40#
+ "231311", # 41#
+ "112133", # 42#
+ "112331", # 43#
+ "132131", # 44#
+ "113123", # 45#
+ "113321", # 46#
+ "133121", # 47#
+ "313121", # 48#
+ "211331", # 49#
+ "231131", # 50#
+ "213113", # 51#
+ "213311", # 52#
+ "213131", # 53#
+ "311123", # 54#
+ "311321", # 55#
+ "331121", # 56#
+ "312113", # 57#
+ "312311", # 58#
+ "332111", # 59#
+ "314111", # 60#
+ "221411", # 61#
+ "431111", # 62#
+ "111224", # 63#
+ "111422", # 64#
+ "121124", # 65#
+ "121421", # 66#
+ "141122", # 67#
+ "141221", # 68#
+ "112214", # 69#
+ "112412", # 70#
+ "122114", # 71#
+ "122411", # 72#
+ "142112", # 73#
+ "142211", # 74#
+ "241211", # 75#
+ "221114", # 76#
+ "413111", # 77#
+ "241112", # 78#
+ "134111", # 79#
+ "111242", # 80#
+ "121142", # 81#
+ "121241", # 82#
+ "114212", # 83#
+ "124112", # 84#
+ "124211", # 85#
+ "411212", # 86#
+ "421112", # 87#
+ "421211", # 88#
+ "212141", # 89#
+ "214121", # 90#
+ "412121", # 91#
+ "111143", # 92#
+ "111341", # 93#
+ "131141", # 94#
+ "114113", # 95#
+ "114311", # 96#
+ "411113", # 97#
+ "411311", # 98#
+ "113141", # 99#
+ "114131", # 100#
+ "311141", # 101#
+ "411131" # 102#
+ );
+ end
+
+ #
+ # Returns the character index.
+ # @param char $char character.
+ # @return int character index or -1 in case of error.
+ # @access private
+ #
+ def GetCharIndex($char)
+ for ($i=0;$i<95;$i++)
+ if (@mChars[$i] == $char)
+ return $i;
+ end
+ end
+ return -1;
+ end
+
+ #
+ # Returns the bar size.
+ # @param int $xres Horizontal resolution.
+ # @param char $char Character.
+ # @return int barcode size.
+ # @access private
+ #
+ def GetBarSize($xres, $char)
+ switch ($char)
+ case '1'
+ $cVal = BCD_C128_BAR_1;
+
+ case '2'
+ $cVal = BCD_C128_BAR_2;
+
+ case '3'
+ $cVal = BCD_C128_BAR_3;
+
+ case '4'
+ $cVal = BCD_C128_BAR_4;
+
+ default
+ $cVal = 0;
+ end
+ end
+ return $cVal# $xres;
+ end
+
+ #
+ # Returns barcode size.
+ # @param int $xres Horizontal resolution.
+ # @return barcode size.
+ # @access private
+ #
+ def GetSize($xres)
+ $len = @mValue.length;
+
+ if ($len == 0) {
+ @mError = "Null value";
+ return false;
+ end
+ $ret = 0;
+ for ($i=0;$i<$len;$i++)
+ if (($id = GetCharIndex(@mValue[$i])) == -1)
+ @mError = "C128B not include the char '".@mValue[$i]."'";
+ return false;
+ else
+ $cset = @mCharSet[$id];
+ $ret += GetBarSize($xres, $cset[0]);
+ $ret += GetBarSize($xres, $cset[1]);
+ $ret += GetBarSize($xres, $cset[2]);
+ $ret += GetBarSize($xres, $cset[3]);
+ $ret += GetBarSize($xres, $cset[4]);
+ $ret += GetBarSize($xres, $cset[5]);
+ end
+ end
+ # length of Check character#
+ $cset = GetCheckCharValue();
+ $CheckSize = 0;
+ for ($i=0;$i<6;$i++)
+ $CheckSize += GetBarSize($cset[$i], $xres);
+ end
+
+ $StartSize = 2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + BCD_C128_BAR_4*$xres;
+ $StopSize = 2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + 2*BCD_C128_BAR_3*$xres;
+
+ return $StartSize + $ret + $CheckSize + $StopSize;
+ end
+
+ #
+ # Returns the check-char value.
+ # @return string.
+ # @access private
+ #
+ def GetCheckCharValue()
+ $len = @mValue.length;
+ $sum = 104; # 'B' type;
+ for ($i=0;$i<$len;$i++)
+ $sum += GetCharIndex(@mValue[$i])# ($i+1);
+ end
+ $check = $sum % 103;
+ return @mCharSet[$check];
+ end
+
+ #
+ # Draws the start code.
+ # @param int $DrawPos Drawing position.
+ # @param int $yPos Vertical position.
+ # @param int $ySize Vertical size.
+ # @param int $xres Horizontal resolution.
+ # @return int drawing position.
+ # @access private
+ #
+ def DrawStart($DrawPos, $yPos, $ySize, $xres)
+ # Start code is '211214'#
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('2', $xres), $ySize);
+ $DrawPos += GetBarSize('2', $xres);
+ $DrawPos += GetBarSize('1', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('1', $xres), $ySize);
+ $DrawPos += GetBarSize('1', $xres);
+ $DrawPos += GetBarSize('2', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('1', $xres), $ySize);
+ $DrawPos += GetBarSize('1', $xres);
+ $DrawPos += GetBarSize('4', $xres);
+ return $DrawPos;
+ end
+
+ #
+ # Draws the stop code.
+ # @param int $DrawPos Drawing position.
+ # @param int $yPos Vertical position.
+ # @param int $ySize Vertical size.
+ # @param int $xres Horizontal resolution.
+ # @return int drawing position.
+ # @access private
+ #
+ def DrawStop($DrawPos, $yPos, $ySize, $xres)
+ # Stop code is '2331112'#
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('2', $xres) , $ySize);
+ $DrawPos += GetBarSize('2', $xres);
+ $DrawPos += GetBarSize('3', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('3', $xres) , $ySize);
+ $DrawPos += GetBarSize('3', $xres);
+ $DrawPos += GetBarSize('1', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('1', $xres) , $ySize);
+ $DrawPos += GetBarSize('1', $xres);
+ $DrawPos += GetBarSize('1', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('2', $xres) , $ySize);
+ $DrawPos += GetBarSize('2', $xres);
+ return $DrawPos;
+ end
+
+ #
+ # Draws the check-char code.
+ # @param int $DrawPos Drawing position.
+ # @param int $yPos Vertical position.
+ # @param int $ySize Vertical size.
+ # @param int $xres Horizontal resolution.
+ # @return int drawing position.
+ # @access private
+ #
+ def DrawCheckChar($DrawPos, $yPos, $ySize, $xres)
+ $cset = GetCheckCharValue();
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[0], $xres) , $ySize);
+ $DrawPos += GetBarSize($cset[0], $xres);
+ $DrawPos += GetBarSize($cset[1], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[2], $xres) , $ySize);
+ $DrawPos += GetBarSize($cset[2], $xres);
+ $DrawPos += GetBarSize($cset[3], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[4], $xres) , $ySize);
+ $DrawPos += GetBarSize($cset[4], $xres);
+ $DrawPos += GetBarSize($cset[5], $xres);
+ return $DrawPos;
+ end
+
+ #
+ # Draws the barcode object.
+ # @param int $xres Horizontal resolution.
+ # @return bool true in case of success.
+ #
+ def DrawObject($xres)
+ $len = @mValue.length;
+ if (($size = GetSize($xres))==0)
+ return false;
+ end
+
+ if (@mStyle & BCS_ALIGN_CENTER) $sPos = (integer)((@mWidth - $size ) / 2);
+ elsif (@mStyle & BCS_ALIGN_RIGHT) $sPos = @mWidth - $size;
+ else $sPos = 0;
+
+ # Total height of bar code -Bars only-#
+ if (@mStyle & BCS_DRAW_TEXT) $ysize = @mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2 - GetFontHeight(@mFont);
+ else $ysize = @mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2;
+
+ # Draw text#
+ if (@mStyle & BCS_DRAW_TEXT)
+ if (@mStyle & BCS_STRETCH_TEXT)
+ for ($i=0;$i<$len;$i++)
+ @DrawChar(@mFont, $sPos+(2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + BCD_C128_BAR_4*$xres)+($size/$len)*$i,
+ $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, @mValue[$i]);
+ else# Center#
+ $text_width = GetFontWidth(@mFont)# @mValue.length;
+ @DrawText(@mFont, $sPos+(($size-$text_width)/2)+(2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + BCD_C128_BAR_4*$xres),
+ $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, @mValue);
+ end
+ end
+
+ $cPos = 0;
+ $DrawPos = @DrawStart($sPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres);
+ do {
+ $c = GetCharIndex(@mValue[$cPos]);
+ $cset = @mCharSet[$c];
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[0], $xres) , $ysize);
+ $DrawPos += GetBarSize($cset[0], $xres);
+ $DrawPos += GetBarSize($cset[1], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[2], $xres) , $ysize);
+ $DrawPos += GetBarSize($cset[2], $xres);
+ $DrawPos += GetBarSize($cset[3], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[4], $xres) , $ysize);
+ $DrawPos += GetBarSize($cset[4], $xres);
+ $DrawPos += GetBarSize($cset[5], $xres);
+ $cPos += 1;
+ end while ($cPos<$len);
+ $DrawPos = @DrawCheckChar($DrawPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres);
+ $DrawPos = @DrawStop($DrawPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres);
+ return true;
+ end
+}
+
+#============================================================+
+# END OF FILE
+#============================================================+
414 lib/barcode/c128cobject.rb
@@ -0,0 +1,414 @@
+
+#============================================================+
+# File name : c128cobject.rb
+# Begin : 2002-07-31
+# Last Update : 2004-12-29
+# Author : Karim Mribti [barcode@mribti.com]
+# : Sam Michaels [swampgas@swampgas.org]
+# : Nicola Asuni [info@tecnick.com]
+# Version : 0.0.8a 2001-04-01 (original code)
+# License : GNU LGPL (Lesser General Public License) 2.1
+# http://www.gnu.org/copyleft/lesser.txt
+# Source Code : http://www.mribti.com/barcode/
+#
+# Description : Code 128-C Barcode Render Class for PHP using
+# the GD graphics library.
+# Code 128-C is numeric only and provides the
+# most efficiency.
+#
+# NOTE:
+# This version contains changes by Nicola Asuni:
+# - porting to Ruby
+# - code style and formatting
+# - automatic php documentation in PhpDocumentor Style
+# (www.phpdoc.org)
+# - minor bug fixing
+#============================================================+
+
+#
+# Code 128-C Barcode Render Class for PHP using the GD graphics library.<br>
+# Code 128-C is numeric only and provides the most efficiency.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+
+#
+# Code 128-C Barcode Render Class for PHP using the GD graphics library.<br>
+# Code 128-C is numeric only and provides the most efficiency.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+class C128CObject extends BarcodeObject {
+
+ #
+ # Class Constructor.
+ # @param int $Width Image width in pixels.
+ # @param int $Height Image height in pixels.
+ # @param int $Style Barcode style.
+ # @param int $Value value to print on barcode.
+ #
+ def __construct($Width, $Height, $Style, $Value)
+ parent::__construct($Width, $Height, $Style);
+ @mValue = $Value;
+ @mChars = array (
+ "00", "01", "02", "03", "04", "05", "06", "07", "08", "09",
+ "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
+ "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
+ "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
+ "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
+ "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
+ "60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
+ "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
+ "80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
+ "90", "91", "92", "93", "94", "95", "96", "97", "98", "99",
+ );
+ @mCharSet = array (
+ "212222", # 00#
+ "222122", # 01#
+ "222221", # 02#
+ "121223", # 03#
+ "121322", # 04#
+ "131222", # 05#
+ "122213", # 06#
+ "122312", # 07#
+ "132212", # 08#
+ "221213", # 09#
+ "221312", # 10#
+ "231212", # 11#
+ "112232", # 12#
+ "122132", # 13#
+ "122231", # 14#
+ "113222", # 15#
+ "123122", # 16#
+ "123221", # 17#
+ "223211", # 18#
+ "221132", # 19#
+ "221231", # 20#
+ "213212", # 21#
+ "223112", # 22#
+ "312131", # 23#
+ "311222", # 24#
+ "321122", # 25#
+ "321221", # 26#
+ "312212", # 27#
+ "322112", # 28#
+ "322211", # 29#
+ "212123", # 30#
+ "212321", # 31#
+ "232121", # 32#
+ "111323", # 33#
+ "131123", # 34#
+ "131321", # 35#
+ "112313", # 36#
+ "132113", # 37#
+ "132311", # 38#
+ "211313", # 39#
+ "231113", # 40#
+ "231311", # 41#
+ "112133", # 42#
+ "112331", # 43#
+ "132131", # 44#
+ "113123", # 45#
+ "113321", # 46#
+ "133121", # 47#
+ "313121", # 48#
+ "211331", # 49#
+ "231131", # 50#
+ "213113", # 51#
+ "213311", # 52#
+ "213131", # 53#
+ "311123", # 54#
+ "311321", # 55#
+ "331121", # 56#
+ "312113", # 57#
+ "312311", # 58#
+ "332111", # 59#
+ "314111", # 60#
+ "221411", # 61#
+ "431111", # 62#
+ "111224", # 63#
+ "111422", # 64#
+ "121124", # 65#
+ "121421", # 66#
+ "141122", # 67#
+ "141221", # 68#
+ "112214", # 69#
+ "112412", # 70#
+ "122114", # 71#
+ "122411", # 72#
+ "142112", # 73#
+ "142211", # 74#
+ "241211", # 75#
+ "221114", # 76#
+ "413111", # 77#
+ "241112", # 78#
+ "134111", # 79#
+ "111242", # 80#
+ "121142", # 81#
+ "121241", # 82#
+ "114212", # 83#
+ "124112", # 84#
+ "124211", # 85#
+ "411212", # 86#
+ "421112", # 87#
+ "421211", # 88#
+ "212141", # 89#
+ "214121", # 90#
+ "412121", # 91#
+ "111143", # 92#
+ "111341", # 93#
+ "131141", # 94#
+ "114113", # 95#
+ "114311", # 96#
+ "411113", # 97#
+ "411311", # 98#
+ "113141", # 99#
+ );
+ end
+
+ #
+ # Returns the character index.
+ # @param char $char character.
+ # @return int character index or -1 in case of error.
+ # @access private
+ #
+ def GetCharIndex($char)
+ for ($i=0;$i<100;$i++)
+ if (@mChars[$i] == $char)
+ return $i;
+ end
+ end
+ return -1;
+ end
+
+ #
+ # Returns the bar size.
+ # @param int $xres Horizontal resolution.
+ # @param char $char Character.
+ # @return int barcode size.
+ # @access private
+ #
+ def GetBarSize($xres, $char)
+ switch ($char)
+ case '1'
+ $cVal = BCD_C128_BAR_1;
+
+ case '2'
+ $cVal = BCD_C128_BAR_2;
+
+ case '3'
+ $cVal = BCD_C128_BAR_3;
+
+ case '4'
+ $cVal = BCD_C128_BAR_4;
+
+ default
+ $cVal = 0;
+ end
+ end
+ return $cVal# $xres;
+ end
+
+ #
+ # Returns barcode size.
+ # @param int $xres Horizontal resolution.
+ # @return barcode size.
+ # @access private
+ #
+ def GetSize($xres)
+ $len = @mValue.length;
+
+ if ($len == 0) {
+ @mError = "Null value";
+ return false;
+ end
+ $ret = 0;
+
+ for ($i=0;$i<$len;$i++)
+ if ((@mValue[$i][0] < 48) || (@mValue[$i][0] > 57))
+ @mError = "Code-128C is numeric only";
+ return false;
+ end
+ end
+
+ if (($len%2) != 0)
+ @mError = "The length of barcode value must be even. You must pad the number with zeros.";
+ return false;
+ end
+
+ for ($i=0;$i<$len;$i+=2)
+ $id = GetCharIndex(@mValue[$i].@mValue[$i+1]);
+ $cset = @mCharSet[$id];
+ $ret += GetBarSize($xres, $cset[0]);
+ $ret += GetBarSize($xres, $cset[1]);
+ $ret += GetBarSize($xres, $cset[2]);
+ $ret += GetBarSize($xres, $cset[3]);
+ $ret += GetBarSize($xres, $cset[4]);
+ $ret += GetBarSize($xres, $cset[5]);
+ end
+ # length of Check character#
+ $cset = GetCheckCharValue();
+ $CheckSize = 0;
+ for ($i=0;$i<6;$i++)
+ $CheckSize += GetBarSize($cset[$i], $xres);
+ end
+
+ $StartSize = 2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + BCD_C128_BAR_4*$xres;
+ $StopSize = 2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + 2*BCD_C128_BAR_3*$xres;
+ return $StartSize + $ret + $CheckSize + $StopSize;
+ end
+
+ #
+ # Returns the check-char value.
+ # @return string.
+ # @access private
+ #
+ def GetCheckCharValue()
+ $len = @mValue.length;
+ $sum = 105; # 'C' type;
+ $m = 0;
+ for ($i=0;$i<$len;$i+=2)
+ $m += 1;
+ $sum += GetCharIndex(@mValue[$i].@mValue[$i+1])# $m;
+ end
+ $check = $sum % 103;
+ return @mCharSet[$check];
+ end
+
+ #
+ # Draws the start code.
+ # @param int $DrawPos Drawing position.
+ # @param int $yPos Vertical position.
+ # @param int $ySize Vertical size.
+ # @param int $xres Horizontal resolution.
+ # @return int drawing position.
+ # @access private
+ #
+ def DrawStart($DrawPos, $yPos, $ySize, $xres)
+ # Start code is '211232'#
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('2', $xres) , $ySize);
+ $DrawPos += GetBarSize('2', $xres);
+ $DrawPos += GetBarSize('1', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('1', $xres) , $ySize);
+ $DrawPos += GetBarSize('1', $xres);
+ $DrawPos += GetBarSize('2', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('3', $xres) , $ySize);
+ $DrawPos += GetBarSize('3', $xres);
+ $DrawPos += GetBarSize('2', $xres);
+ return $DrawPos;
+ end
+
+ #
+ # Draws the stop code.
+ # @param int $DrawPos Drawing position.
+ # @param int $yPos Vertical position.
+ # @param int $ySize Vertical size.
+ # @param int $xres Horizontal resolution.
+ # @return int drawing position.
+ # @access private
+ #
+ def DrawStop($DrawPos, $yPos, $ySize, $xres)
+ # Stop code is '2331112'#
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('2', $xres) , $ySize);
+ $DrawPos += GetBarSize('2', $xres);
+ $DrawPos += GetBarSize('3', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('3', $xres) , $ySize);
+ $DrawPos += GetBarSize('3', $xres);
+ $DrawPos += GetBarSize('1', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('1', $xres) , $ySize);
+ $DrawPos += GetBarSize('1', $xres);
+ $DrawPos += GetBarSize('1', $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize('2', $xres) , $ySize);
+ $DrawPos += GetBarSize('2', $xres);
+ return $DrawPos;
+ end
+
+ #
+ # Draws the check-char code.
+ # @param int $DrawPos Drawing position.
+ # @param int $yPos Vertical position.
+ # @param int $ySize Vertical size.
+ # @param int $xres Horizontal resolution.
+ # @return int drawing position.
+ # @access private
+ #
+ def DrawCheckChar($DrawPos, $yPos, $ySize, $xres)
+ $cset = GetCheckCharValue();
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[0], $xres) , $ySize);
+ $DrawPos += GetBarSize($cset[0], $xres);
+ $DrawPos += GetBarSize($cset[1], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[2], $xres) , $ySize);
+ $DrawPos += GetBarSize($cset[2], $xres);
+ $DrawPos += GetBarSize($cset[3], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[4], $xres) , $ySize);
+ $DrawPos += GetBarSize($cset[4], $xres);
+ $DrawPos += GetBarSize($cset[5], $xres);
+ return $DrawPos;
+ end
+
+ #
+ # Draws the barcode object.
+ # @param int $xres Horizontal resolution.
+ # @return bool true in case of success.
+ #
+ def DrawObject($xres)
+ $len = @mValue.length;
+ if (($size = GetSize($xres))==0)
+ return false;
+ end
+
+ if (@mStyle & BCS_ALIGN_CENTER) $sPos = (integer)((@mWidth - $size ) / 2);
+ elsif (@mStyle & BCS_ALIGN_RIGHT) $sPos = @mWidth - $size;
+ else $sPos = 0;
+
+ # Total height of bar code -Bars only-#
+ if (@mStyle & BCS_DRAW_TEXT) $ysize = @mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2 - GetFontHeight(@mFont);
+ else $ysize = @mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2;
+
+ # Draw text#
+ if (@mStyle & BCS_DRAW_TEXT)
+ if (@mStyle & BCS_STRETCH_TEXT)
+ for ($i=0;$i<$len;$i++)
+ @DrawChar(@mFont, $sPos+(2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + BCD_C128_BAR_4*$xres)+($size/$len)*$i,
+ $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, @mValue[$i]);
+ else# Center#
+ $text_width = GetFontWidth(@mFont) * @mValue.length;
+ @DrawText(@mFont, $sPos+(($size-$text_width)/2)+(2*BCD_C128_BAR_2*$xres + 3*BCD_C128_BAR_1*$xres + BCD_C128_BAR_4*$xres),
+ $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, @mValue);
+ end
+ end
+
+ $cPos = 0;
+ $DrawPos = @DrawStart($sPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres);
+ do {
+ $c = GetCharIndex(@mValue[$cPos].@mValue[$cPos+1]);
+ $cset = @mCharSet[$c];
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[0], $xres) , $ysize);
+ $DrawPos += GetBarSize($cset[0], $xres);
+ $DrawPos += GetBarSize($cset[1], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[2], $xres) , $ysize);
+ $DrawPos += GetBarSize($cset[2], $xres);
+ $DrawPos += GetBarSize($cset[3], $xres);
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, GetBarSize($cset[4], $xres) , $ysize);
+ $DrawPos += GetBarSize($cset[4], $xres);
+ $DrawPos += GetBarSize($cset[5], $xres);
+ $cPos += 2;
+ end while ($cPos<$len);
+ $DrawPos = @DrawCheckChar($DrawPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres);
+ $DrawPos = @DrawStop($DrawPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres);
+ return true;
+ end
+}
+
+#============================================================+
+# END OF FILE
+#============================================================+
+
281 lib/barcode/c39object.rb
@@ -0,0 +1,281 @@
+
+#============================================================+
+# File name : c39object.rb
+# Begin : 2002-07-31
+# Last Update : 2004-12-29
+# Author : Karim Mribti [barcode@mribti.com]
+# : Nicola Asuni [info@tecnick.com]
+# Version : 0.0.8a 2001-04-01 (original code)
+# License : GNU LGPL (Lesser General Public License) 2.1
+# http://www.gnu.org/copyleft/lesser.txt
+# Source Code : http://www.mribti.com/barcode/
+#
+# Description : Code 39 Barcode Render Class for PHP using
+# the GD graphics library.
+# Code 39 is an alphanumeric bar code that can
+# encode decimal number, case alphabet and some
+# special symbols.
+#
+# NOTE:
+# This version contains changes by Nicola Asuni:
+# - porting to Ruby
+# - code style and formatting
+# - automatic php documentation in PhpDocumentor Style
+# (www.phpdoc.org)
+# - minor bug fixing
+#============================================================+
+
+#
+# Code 39 Barcode Render Class.<br>
+# Code 39 is an alphanumeric bar code that can encode decimal number, case alphabet and some special symbols.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+
+#
+# Code 39 Barcode Render Class.<br>
+# Code 39 is an alphanumeric bar code that can encode decimal number, case alphabet and some special symbols.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+class C39Object extends BarcodeObject {
+
+ #
+ # Class Constructor.
+ # @param int $Width Image width in pixels.
+ # @param int $Height Image height in pixels.
+ # @param int $Style Barcode style.
+ # @param int $Value value to print on barcode.
+ #
+ def __construct($Width, $Height, $Style, $Value)
+ parent::__construct($Width, $Height, $Style);
+ @mValue = $Value;
+ @mChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-.#$/+%";
+ @mCharSet = array (
+ # 0 # "000110100",
+ # 1 # "100100001",
+ # 2 # "001100001",
+ # 3 # "101100000",
+ # 4 # "000110001",
+ # 5 # "100110000",
+ # 6 # "001110000",
+ # 7 # "000100101",
+ # 8 # "100100100",
+ # 9 # "001100100",
+ # A # "100001001",
+ # B # "001001001",
+ # C # "101001000",
+ # D # "000011001",
+ # E # "100011000",
+ # F # "001011000",
+ # G # "000001101",
+ # H # "100001100",
+ # I # "001001100",
+ # J # "000011100",
+ # K # "100000011",
+ # L # "001000011",
+ # M # "101000010",
+ # N # "000010011",
+ # O # "100010010",
+ # P # "001010010",
+ # Q # "000000111",
+ # R # "100000110",
+ # S # "001000110",
+ # T # "000010110",
+ # U # "110000001",
+ # V # "011000001",
+ # W # "111000000",
+ # X # "010010001",
+ # Y # "110010000",
+ # Z # "011010000",
+ # - # "010000101",
+ # . # "110000100",
+ # SP# "011000100",
+ /*# # "010010100",
+ # $ # "010101000",
+ # / # "010100010",
+ # + # "010001010",
+ # % # "000101010"
+ );
+ end
+
+ #
+ # Returns the character index.
+ # @param char $char character.
+ # @return int character index or -1 in case of error.
+ # @access private
+ #
+ def GetCharIndex($char)
+ for ($i=0;$i<44;$i++)
+ if (@mChars[$i] == $char)
+ return $i;
+ end
+ end
+ return -1;
+ end
+
+ #
+ # Returns barcode size.
+ # @param int $xres Horizontal resolution.
+ # @return barcode size.
+ # @access private
+ #
+ def GetSize($xres)
+ $len = @mValue.length;
+
+ if ($len == 0) {
+ @mError = "Null value";
+ return false;
+ end
+
+ for ($i=0;$i<$len;$i++)
+ if (GetCharIndex(@mValue[$i]) == -1 || @mValue[$i] == '*')
+ # The asterisk is only used as a start and stop code#
+ @mError = "C39 not include the char '".@mValue[$i]."'";
+ return false;
+ end
+ end
+
+ # Start, Stop is 010010100 == '*' #
+ $StartSize = BCD_C39_NARROW_BAR# $xres# 6 + BCD_C39_WIDE_BAR# $xres# 3;
+ $StopSize = BCD_C39_NARROW_BAR# $xres# 6 + BCD_C39_WIDE_BAR# $xres# 3;
+ $CharSize = BCD_C39_NARROW_BAR# $xres# 6 + BCD_C39_WIDE_BAR# $xres# 3; # Same for all chars#
+
+ return $CharSize# $len + $StartSize + $StopSize + # Space between chars# BCD_C39_NARROW_BAR# $xres# ($len-1);
+ end
+
+ #
+ # Draws the start code.
+ # @param int $DrawPos Drawing position.
+ # @param int $yPos Vertical position.
+ # @param int $ySize Vertical size.
+ # @param int $xres Horizontal resolution.
+ # @return int drawing position.
+ # @access private
+ #
+ def DrawStart($DrawPos, $yPos, $ySize, $xres)
+ # Start code is '*'#
+ $narrow = BCD_C39_NARROW_BAR# $xres;
+ $wide = BCD_C39_WIDE_BAR# $xres;
+ @DrawSingleBar($DrawPos, $yPos, $narrow , $ySize);
+ $DrawPos += $narrow;
+ $DrawPos += $wide;
+ @DrawSingleBar($DrawPos, $yPos, $narrow , $ySize);
+ $DrawPos += $narrow;
+ $DrawPos += $narrow;
+ @DrawSingleBar($DrawPos, $yPos, $wide , $ySize);
+ $DrawPos += $wide;
+ $DrawPos += $narrow;
+ @DrawSingleBar($DrawPos, $yPos, $wide , $ySize);
+ $DrawPos += $wide;
+ $DrawPos += $narrow;
+ @DrawSingleBar($DrawPos, $yPos, $narrow, $ySize);
+ $DrawPos += $narrow;
+ $DrawPos += $narrow; # Space between chars#
+ return $DrawPos;
+ end
+
+ #
+ # Draws the stop code.
+ # @param int $DrawPos Drawing position.
+ # @param int $yPos Vertical position.
+ # @param int $ySize Vertical size.
+ # @param int $xres Horizontal resolution.
+ # @return int drawing position.
+ # @access private
+ #
+ def DrawStop($DrawPos, $yPos, $ySize, $xres)
+ # Stop code is '*'#
+ $narrow = BCD_C39_NARROW_BAR# $xres;
+ $wide = BCD_C39_WIDE_BAR# $xres;
+ @DrawSingleBar($DrawPos, $yPos, $narrow , $ySize);
+ $DrawPos += $narrow;
+ $DrawPos += $wide;
+ @DrawSingleBar($DrawPos, $yPos, $narrow , $ySize);
+ $DrawPos += $narrow;
+ $DrawPos += $narrow;
+ @DrawSingleBar($DrawPos, $yPos, $wide , $ySize);
+ $DrawPos += $wide;
+ $DrawPos += $narrow;
+ @DrawSingleBar($DrawPos, $yPos, $wide , $ySize);
+ $DrawPos += $wide;
+ $DrawPos += $narrow;
+ @DrawSingleBar($DrawPos, $yPos, $narrow, $ySize);
+ $DrawPos += $narrow;
+ return $DrawPos;
+ end
+
+ #
+ # Draws the barcode object.
+ # @param int $xres Horizontal resolution.
+ # @return bool true in case of success.
+ #
+ def DrawObject($xres)
+ $len = @mValue.length;
+
+ $narrow = BCD_C39_NARROW_BAR# $xres;
+ $wide = BCD_C39_WIDE_BAR# $xres;
+
+ if (($size = GetSize($xres))==0)
+ return false;
+ end
+
+ $cPos = 0;
+ if (@mStyle & BCS_ALIGN_CENTER) $sPos = (integer)((@mWidth - $size ) / 2);
+ elsif (@mStyle & BCS_ALIGN_RIGHT) $sPos = @mWidth - $size;
+ else $sPos = 0;
+
+ # Total height of bar code -Bars only-#
+ if (@mStyle & BCS_DRAW_TEXT) $ysize = @mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2 - GetFontHeight(@mFont);
+ else $ysize = @mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2;
+
+ # Draw text#
+ if (@mStyle & BCS_DRAW_TEXT)
+ if (@mStyle & BCS_STRETCH_TEXT)
+ for ($i=0;$i<$len;$i++)
+ @DrawChar(@mFont, $sPos+($narrow*6+$wide*3)+($size/$len)*$i,
+ $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, @mValue[$i]);
+ else# Center#
+ $text_width = GetFontWidth(@mFont)# @mValue.length;
+ @DrawText(@mFont, $sPos+(($size-$text_width)/2)+($narrow*6+$wide*3),
+ $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, @mValue);
+ end
+ end
+
+ $DrawPos = @DrawStart($sPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres);
+ do {
+ $c = GetCharIndex(@mValue[$cPos]);
+ $cset = @mCharSet[$c];
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, ($cset[0] == '0') ? $narrow : $wide , $ysize);
+ $DrawPos += ($cset[0] == '0') ? $narrow : $wide;
+ $DrawPos += ($cset[1] == '0') ? $narrow : $wide;
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, ($cset[2] == '0') ? $narrow : $wide , $ysize);
+ $DrawPos += ($cset[2] == '0') ? $narrow : $wide;
+ $DrawPos += ($cset[3] == '0') ? $narrow : $wide;
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, ($cset[4] == '0') ? $narrow : $wide , $ysize);
+ $DrawPos += ($cset[4] == '0') ? $narrow : $wide;
+ $DrawPos += ($cset[5] == '0') ? $narrow : $wide;
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, ($cset[6] == '0') ? $narrow : $wide , $ysize);
+ $DrawPos += ($cset[6] == '0') ? $narrow : $wide;
+ $DrawPos += ($cset[7] == '0') ? $narrow : $wide;
+ @DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, ($cset[8] == '0') ? $narrow : $wide , $ysize);
+ $DrawPos += ($cset[8] == '0') ? $narrow : $wide;
+ $DrawPos += $narrow; # Space between chars#
+ $cPos += 1;
+ end while ($cPos<$len);
+ $DrawPos = @DrawStop($DrawPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres);
+ return true;
+ end
+}
+
+#============================================================+
+# END OF FILE
+#============================================================+
216 lib/barcode/i25object.rb
@@ -0,0 +1,216 @@
+
+#============================================================+
+# File name : i25aobject.rb
+# Begin : 2002-07-31
+# Last Update : 2004-12-29
+# Author : Karim Mribti [barcode@mribti.com]
+# : Nicola Asuni [info@tecnick.com]
+# Version : 0.0.8a 2001-04-01 (original code)
+# License : GNU LGPL (Lesser General Public License) 2.1
+# http://www.gnu.org/copyleft/lesser.txt
+# Source Code : http://www.mribti.com/barcode/
+#
+# Description : I25 Barcode Render Class for PHP using
+# the GD graphics library.
+# Interleaved 2 of 5 is a numeric only bar code
+# with a optional check number.
+#
+# NOTE:
+# This version contains changes by Nicola Asuni:
+# - porting to Ruby
+# - code style and formatting
+# - automatic php documentation in PhpDocumentor Style
+# (www.phpdoc.org)
+# - minor bug fixing
+#============================================================+
+
+#
+# I25 Barcode Render Class for PHP using the GD graphics library.<br<
+# Interleaved 2 of 5 is a numeric only bar code with a optional check number.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+
+#
+# I25 Barcode Render Class for PHP using the GD graphics library.<br<
+# Interleaved 2 of 5 is a numeric only bar code with a optional check number.
+# @author Karim Mribti, Nicola Asuni
+# @name BarcodeObject
+# @package com.tecnick.tcpdf
+# @@version 0.0.8a 2001-04-01 (original code)
+# @since 2001-03-25
+# @license http://www.gnu.org/copyleft/lesser.html LGPL
+#
+class I25Object extends BarcodeObject {
+
+ #
+ # Class Constructor.