here it is.. auto-resize text : (I used a few line of code from Code128Auto.au3)
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <StringSize.au3>
#include "Zint.au3"
$LabelWidth = 29
$LabelLenght = 90
$FontSize = 24
Global $pZB = ZBarcode_Create()
If @error Then Exit MsgBox(16, "ERROR", "An error occured!" & @CRLF & "Error code = " & @error, 10)
;~ Global $t_zint_symbol = DllStructCreate($tag_zint_symbol, $pZB), $sText = "12340984576456789 ;-)"
;~ Global $t_zint_symbol = DllStructCreate($tag_zint_symbol, $pZB), $sText = "12340 ;-)"
Global $t_zint_symbol = DllStructCreate($tag_zint_symbol, $pZB), $sText = "12 ;-)"
With $t_zint_symbol
.symbology = $BARCODE_CODE128
.scale = 1
;~ .width = $LabelLenght ;~ not working .. need to test that??
.height = $LabelWidth
EndWith
If Not ZBarcode_Encode_and_Buffer_Vector($pZB, $sText) Then Exit MsgBox(16, "ERROR", "Unable to encode!" & @CRLF & "Error code = " & @error, 10)
Global $tVector = DllStructCreate($tag_zint_vector, $t_zint_symbol.vector)
Global $tVector_Rect = DllStructCreate($tag_zint_vector_rect, $tVector.rectangles)
_GDIPlus_Startup()
Global $hBitmap = _GDIPlus_BitmapCreateFromScan0($tVector.width, $tVector.heigth, $GDIP_PXF24RGB), $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap), $hBrush = _GDIPlus_BrushCreateSolid()
_GDIPlus_GraphicsClear($hCanvas, 0xFFFFFFFF)
_GDIPlus_BrushSetSolidColor($hBrush, BitAND($tVector_Rect.colour, 0xFF000000)) ;~ don't need to be in the While
While $tVector_Rect.Next
_GDIPlus_GraphicsFillRect($hCanvas, $tVector_Rect.x / 2, $tVector_Rect.y / 2, $tVector_Rect.width / 2, ($tVector_Rect.height / 2), $hBrush) ;~ working line
$tVector_Rect = DllStructCreate($tag_zint_vector_rect, $tVector_Rect.Next)
WEnd
Global $tVector_String = DllStructCreate($tag_zint_vector_string, $tVector.strings)
$i = _StringSize(String($sText), $FontSize, Default, Default, "Arial Black")
$cx = ($LabelLenght / 2) - ($i[2] * 1.16 / 2)
While $cx < 0
$FontSize -= 1
$i = _StringSize(String($sText), $FontSize, Default, Default, "Arial Black")
$cx = ($LabelLenght / 2) - ($i[2] * 1.16 / 2)
WEnd
_GDIPlus_GraphicsSetTextRenderingHint($hCanvas, 3)
If $FontSize < 10 Then $FontSize = 10
_GDIPlus_GraphicsDrawString($hCanvas, $sText, 0, ($LabelWidth / 2) + ($tVector_Rect.height / 2) - ($FontSize / 2), "Arial Black", $FontSize)
Global Const $hGUI = GUICreate("Test Bar Code 128", $tVector.width, $tVector.heigth)
GUISetState(@SW_SHOW)
Global Const $hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImageRect($hGfx, $hBitmap, 0, 0, $tVector.width, $tVector.heigth)
_GDIPlus_GraphicsDispose($hCanvas)
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_ImageDispose($hBitmap)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_Shutdown()
ZBarcode_Delete($pZB)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE