Răsfoiți Sursa

Other ongoing modules to squirrel
sqfltk is for interface FLTK GUI library
sqfpdf is for my c++ port of fpdf library

mingodad 13 ani în urmă
părinte
comite
d193ea26f1
6 a modificat fișierele cu 5157 adăugiri și 0 ștergeri
  1. 2911 0
      ext/fpdf.cpp
  2. 321 0
      ext/pdf-font.cpp
  3. 98 0
      ext/pdf-font.h
  4. 780 0
      ext/sqfltk.cpp
  5. 15 0
      ext/sqfltk.h
  6. 1032 0
      ext/sqfpdf.cpp

+ 2911 - 0
ext/fpdf.cpp

@@ -0,0 +1,2911 @@
+// fpdf.cpp
+//
+
+#include "fpdf.h"
+#line 12 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+//#define PDF_USING_ZLIB 1
+#define FPDF_VERSION "1.7"
+//#include "sqlite3.h"
+//#define pdf_vsnprintf sqlite3_ivsnprintf //vsnprintf
+//#define pdf_snprintf sqlite3_isnprintf //snprintf
+#define pdf_vsnprintf vsnprintf //vsnprintf
+#define pdf_snprintf snprintf //snprintf
+#include <cstdarg>
+#include <cstdio>
+#include <cstring>
+#include <ctime>
+#include <cmath>
+#ifdef PDF_USING_ZLIB
+#include "zlib.h"
+#endif
+//#include "duma.h"
+#line 2252 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+#define M_SOF0  0xC0     // Start Of Frame N
+#define M_SOF1  0xC1     // N indicates which compression process
+#define M_SOF2  0xC2     // Only SOF0-SOF2 are now in common use
+#define M_SOF3  0xC3
+#define M_SOF5  0xC5     // NB: codes C4 and CC are NOT SOF markers
+#define M_SOF6  0xC6
+#define M_SOF7  0xC7
+#define M_SOF9  0xC9
+#define M_SOF10 0xCA
+#define M_SOF11 0xCB
+#define M_SOF13 0xCD
+#define M_SOF14 0xCE
+#define M_SOF15 0xCF
+#define M_SOI   0xD8
+#define M_EOI   0xD9     // End Of Image (end of datastream)
+#define M_SOS   0xDA     // Start Of Scan (begins compressed data)
+#define M_COM   0xFE     // COMment
+
+#define M_PSEUDO 0xFFD8  // pseudo marker for start of image(byte 0)
+#define LZZ_INLINE inline
+#ifdef PDF_USING_ZLIB
+#line 30 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+std::string & gzcompress (std::string & dest, std::string const & src)
+#line 31 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+{
+    z_stream stream;
+    int err;
+
+    int nExtraChunks;
+    size_t src_len = src.size();
+    size_t dest_len = 2048 + src_len;
+    dest.resize(dest_len);
+
+    stream.next_in = (Bytef*)&src[0];
+    stream.avail_in = (uInt)src_len;
+
+    stream.zalloc = (alloc_func)0;
+    stream.zfree = (free_func)0;
+    stream.opaque = (voidpf)0;
+
+    //err = deflateInit(&stream, Z_DEFAULT_COMPRESSION);
+    err = deflateInit(&stream, Z_BEST_SPEED);
+    if (err != Z_OK) throw "Could not initialize zstream !";
+
+    nExtraChunks = 0;
+    do
+    {
+        stream.next_out = (unsigned char*)&dest[0];
+        stream.avail_out = dest_len;
+        err = deflate(&stream, Z_FINISH);
+        if (err == Z_STREAM_END )
+            break;
+        if (err != Z_OK)
+        {
+            inflateEnd(&stream);
+            throw "Could not uncompress data !";
+        }
+        nExtraChunks += 1;
+    }
+    while (stream.avail_out == 0);
+
+    dest.resize(stream.total_out);
+
+    err = deflateEnd(&stream);
+    if (nExtraChunks || (err != Z_OK)) throw "Could finalize zstream !";
+    return dest;
+}
+#line 75 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+std::string & gzuncompress (std::string & dest, std::string const & src)
+#line 76 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+{
+    z_stream stream;
+    int err;
+
+    int nExtraChunks;
+    size_t src_len = src.size();
+    size_t dest_len = 2048 + src_len*5;
+    dest.resize(dest_len);
+
+    stream.next_in = (Bytef*)&src[0];
+    stream.avail_in = (uInt)src_len;
+
+    stream.zalloc = (alloc_func)0;
+    stream.zfree = (free_func)0;
+
+    err = inflateInit(&stream);
+    if (err != Z_OK) throw "Could not initialize zstream !";
+
+    nExtraChunks = 0;
+    do
+    {
+        stream.next_out = (unsigned char*)&dest[0];
+        stream.avail_out = dest_len;
+        err = inflate(&stream, Z_FINISH);
+        if (err == Z_STREAM_END )
+            break;
+        if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
+            err = Z_DATA_ERROR;
+        if (err != Z_BUF_ERROR)
+        {
+            inflateEnd(&stream);
+            throw "Could not uncompress data !";
+        }
+        nExtraChunks += 1;
+    }
+    while (stream.avail_out == 0);
+
+    dest.resize(stream.total_out);
+
+    err = inflateEnd(&stream);
+    if (nExtraChunks || (err != Z_OK)) throw "Could finalize zstream !";
+    return dest;
+}
+#endif
+#line 132 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+char const * FPDF_FONTPATH = 0;
+#line 261 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+FPDF::~ FPDF ()
+#line 262 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        font_map_t::iterator iter = m_fonts.begin();
+        font_map_t::iterator iend = m_fonts.end();
+        while(iter != iend)
+        {
+            delete iter->second;
+            ++iter;
+        }
+    }
+#line 272 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+FPDF::FPDF ()
+#line 273 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        reset(e_orientation_portrait, e_mm, e_A4);
+    }
+#line 277 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+FPDF::FPDF (e_orientation orientation, e_units unit, e_page_sizes psize)
+#line 278 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        reset(orientation, unit, psize);
+    }
+#line 282 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+FPDF::FPDF (char orientation, char const * unit, char const * psize)
+#line 283 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        e_orientation eo = orientation == 'L' ? e_orientation_landscape : e_orientation_portrait;
+        e_units eu;
+        e_page_sizes es;
+        if(strcasecmp(unit, "pt")==0) eu = e_pt;
+        else if(strcasecmp(unit, "cm")==0) eu = e_cm;
+        else if(strcasecmp(unit, "in")==0) eu = e_in;
+        else eu = e_mm;
+
+        if(strcasecmp(psize, "a3")==0) es = e_A3;
+        else if(strcasecmp(psize, "a5")==0) es = e_A5;
+        else if(strcasecmp(psize, "letter")==0) es = e_Letter;
+        else if(strcasecmp(psize, "legal")==0) es = e_Legal;
+        else es = e_A4;
+
+        reset(eo, eu, es);
+    }
+#line 301 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::reset (e_orientation orientation, e_units unit, e_page_sizes psize)
+#line 302 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Scale factor
+        switch(unit)
+        {
+        case e_pt:
+            m_k = 1;
+            break;
+        case e_mm:
+            m_k = 72/25.4;
+            break;
+        case e_cm:
+            m_k = 72/2.54;
+            break;
+        case e_in:
+            m_k = 72;
+            break;
+        default:
+            Error("Incorrect unit: %s", unit);
+        }
+
+        // Some checks
+        _dochecks();
+        // Initialization of properties
+        m_page = 0;
+        m_pages.clear();
+        m_PageSizes.clear();
+        m_offsets.clear();
+        m_fonts.clear();
+        m_FontFiles.clear();
+        m_diffs.clear();
+        m_images.clear();
+        m_PageLinks.clear();
+        m_links.clear();
+        m_extgstates.clear();
+        m_offsets.resize(3, 0);
+        m_n = 2;
+        m_buffer.clear();
+        m_buffer.reserve(1024);
+        //this->buffer = "";
+        //this->m_pages = array();
+        //this->PageSizes = array();
+        m_state = 0;
+        //this->fonts = array();
+        //this->FontFiles = array();
+        //this->diffs = array();
+        //this->images = array();
+        //this->links = array();
+        m_InHeader = false;
+        m_InFooter = false;
+        m_lasth = 0;
+        //this->FontFamily = "";
+        //this->FontStyle = "";
+        m_FontSizePt = 12;
+        m_underline = false;
+        m_DrawColor = "0 G";
+        m_DrawColor_rgb = {0,0,0,0};
+        m_FillColor = "0 g";
+        m_FillColor_rgb = {0,0,0,0};
+        m_TextColor = "0 g";
+        m_TextColor_rgb = {0,0,0,0};
+        m_ColorFlag = false;
+        m_ws = 0;
+        // Font path
+        if(FPDF_FONTPATH)
+        {
+            m_fontpath = FPDF_FONTPATH;
+            char clast = *m_fontpath.rbegin();
+            if(clast != '/' && clast != '\\')
+                m_fontpath += "/";
+        }
+#if 0
+        else if(is_dir(dirname(__FILE__) + "/font"))
+            m_fontpath = dirname(__FILE__) + "/font/";
+#endif
+        else
+            m_fontpath.clear();
+
+        m_CurrentFont = 0;
+
+        st_pagesize page_size;
+        _getpagesize(page_size, psize);
+        m_DefPageSize = page_size;
+        m_CurPageSize = page_size;
+        // Page orientation
+        switch(orientation)
+        {
+        case e_orientation_portrait:
+        {
+            m_DefOrientation = e_orientation_portrait;
+            m_w = page_size.w;
+            m_h = page_size.h;
+        }
+        break;
+        case e_orientation_landscape:
+        {
+            m_DefOrientation = e_orientation_landscape;
+            m_w = page_size.h;
+            m_h = page_size.w;
+        }
+        break;
+        default:
+            Error("Incorrect orientation: %d", orientation);
+        }
+
+        m_CurOrientation = m_DefOrientation;
+        m_wPt = m_w * m_k;
+        m_hPt = m_h * m_k;
+        m_angle = 0;
+        // Page margins (1 cm)
+        pdf_float_t margin = 28.35/m_k;
+        SetMargins(margin,margin);
+        // Interior cell margin (1 mm)
+        m_cMargin = margin/10.0;
+        // Line width (0.2 mm)
+        m_LineWidth = .567/m_k;
+        // Automatic page break
+        SetAutoPageBreak(true,2*margin);
+        // Default display mode
+        SetDisplayMode(e_zoom_default);
+        m_CustomZoom = 0;
+        // Enable compression
+        SetCompression(true);
+        // Set default PDF version number
+        m_PDFVersion = "1.3";
+
+        m_doubleSided=false;
+        m_xDelta=0;
+        m_innerMargin=10;
+        m_outerMargin=10;
+        m_n_js = 0;
+    }
+#line 434 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetDoubleSided (pdf_float_t inner, pdf_float_t outer)
+#line 435 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        if(outer != inner)
+        {
+            m_doubleSided=true;
+            m_outerMargin=outer;
+            m_innerMargin=inner;
+        }
+    }
+#line 444 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetMargins (pdf_float_t left, pdf_float_t top, pdf_float_t right)
+#line 445 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set left, top and right margins
+        m_lMargin = left;
+        m_tMargin = top;
+        m_rMargin = (right==0.0f) ? left : right;
+    }
+#line 452 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetLeftMargin (pdf_float_t margin)
+#line 453 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set left margin
+        m_lMargin = margin;
+        if(m_page > 0 && m_x < margin)
+            m_x = margin;
+    }
+#line 482 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetAutoPageBreak (bool b, pdf_float_t margin)
+#line 483 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set auto page break mode and triggering margin
+        m_AutoPageBreak = b;
+        m_bMargin = margin;
+        m_PageBreakTrigger = m_h-margin;
+    }
+#line 490 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::CheckPageBreak (pdf_float_t height)
+#line 491 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        //If the height h would cause an overflow, add a new page immediately
+        if(GetY()+height > m_PageBreakTrigger)
+        AddPage(m_CurOrientation);
+    }
+#line 507 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetDisplayMode (e_zoom_mode zoom, e_layout_mode layout)
+#line 508 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set display mode in viewer
+        if(zoom==e_zoom_fullpage || zoom==e_zoom_fullwidth ||
+                zoom==e_zoom_real || zoom==e_zoom_default)
+            m_ZoomMode = zoom;
+        else
+            Error("Incorrect zoom display mode %d", zoom);
+        if(layout==e_layout_single || layout==e_layout_continuous ||
+                layout==e_layout_two || layout==e_layout_default)
+            m_LayoutMode = layout;
+        else
+            Error("Incorrect layout display mode: %d", layout);
+    }
+#line 522 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetCompression (bool compress)
+#line 523 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set page compression
+#ifndef PDF_USING_ZLIB
+        m_compress = false;
+#else
+        m_compress = compress;
+#endif
+    }
+#line 532 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetTitle (char const * title)
+#line 533 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Title of document
+        m_title = title;
+    }
+#line 538 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetSubject (char const * subject)
+#line 539 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Subject of document
+        m_subject = subject;
+    }
+#line 544 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetAuthor (char const * author)
+#line 545 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Author of document
+        m_author = author;
+    }
+#line 550 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetKeywords (char const * keywords)
+#line 551 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Keywords of document
+        m_keywords = keywords;
+    }
+#line 556 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetCreator (char const * creator)
+#line 557 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Creator of document
+        m_creator = creator;
+    }
+#line 562 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::AliasNbPages (char const * alias)
+#line 563 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Define an alias for total number of pages
+        m_AliasNbPages = alias;
+    }
+#line 574 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Error (char const * msg, ...)
+#line 575 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Fatal error
+        va_list args;
+        va_start( args, msg );
+        pdf_vsnprintf(m_scratch_buf, sizeof(m_scratch_buf), msg, args);
+        va_end( args );
+        std::string error_msg = "FPDF error: ";
+        error_msg +=  m_scratch_buf;
+        throw error_msg;
+    }
+#line 592 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Close ()
+#line 593 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Terminate document
+        if(m_state==3) return;
+        if(m_page==0) AddPage();
+        // Page footer
+        m_InFooter = true;
+        Footer();
+        m_InFooter = false;
+        // Close page
+        _endpage();
+        // Close document
+        _enddoc();
+    }
+#line 607 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::AddPage (e_orientation orientation, st_pagesize * psize)
+#line 608 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Start a new page
+        if(m_state==0) Open();
+        std::string family = m_FontFamily;
+        std::string style = m_FontStyle;
+        if(m_underline) style += "U";
+        pdf_float_t fontsize = m_FontSizePt;
+        pdf_float_t lw = m_LineWidth;
+        std::string dc = m_DrawColor;
+        std::string fc = m_FillColor;
+        std::string tc = m_TextColor;
+        bool cf = m_ColorFlag;
+        if(m_page > 0)
+        {
+            // Page footer
+            m_InFooter = true;
+            Footer();
+            m_InFooter = false;
+            // Close page
+            _endpage();
+        }
+        // Start new page
+        _beginpage(orientation,psize);
+        // Set line cap style to square
+        _out("2 J");
+        // Set line width
+        m_LineWidth = lw;
+        _outfmt(true, "%.2f w", lw*m_k);
+        // Set font
+        if(!family.empty()) SetFont(family.c_str(),style.c_str(),fontsize);
+        // Set colors
+        m_DrawColor = dc;
+        if(dc != "0 G") _out(dc);
+        m_FillColor = fc;
+        if(fc != "0 g") _out(fc);
+        m_TextColor = tc;
+        m_ColorFlag = cf;
+        // Page header
+        m_InHeader = true;
+        Header();
+        m_InHeader = false;
+        // Restore line width
+        if(m_LineWidth != lw)
+        {
+            m_LineWidth = lw;
+            _outfmt(true, "%.2f w", lw*m_k);
+        }
+        // Restore font
+        if(!family.empty()) SetFont(family.c_str(),style.c_str(),fontsize);
+        // Restore colors
+        if(m_DrawColor != dc)
+        {
+            m_DrawColor = dc;
+            _out(dc);
+        }
+        if(m_FillColor != fc)
+        {
+            m_FillColor = fc;
+            _out(fc);
+        }
+        m_TextColor = tc;
+        m_ColorFlag = cf;
+    }
+#line 672 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Header ()
+#line 673 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {}
+#line 677 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Footer ()
+#line 678 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {}
+#line 688 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetDrawColor (unsigned char r)
+#line 689 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set color for all stroking operations
+        m_DrawColor_rgb = {r,r,r,0};
+        pdf_sprintf(m_DrawColor, "%.3f G", r/255.0);
+        if(m_page>0) _out(m_DrawColor);
+    }
+#line 696 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetDrawColor (unsigned char r, unsigned char g, unsigned char b)
+#line 697 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set color for all stroking operations
+        m_DrawColor_rgb = {r,g,b,0};
+        pdf_sprintf(m_DrawColor, "%.3f %.3f %.3f RG", r/255.0, g/255.0, b/255.0);
+        if(m_page>0) _out(m_DrawColor);
+    }
+#line 712 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetFillColor (unsigned char r)
+#line 713 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set color for all filling operations
+        m_FillColor_rgb = {r,r,r,0};
+        pdf_sprintf(m_FillColor, "%.3f g", r/255.0);
+        m_ColorFlag = (m_FillColor != m_TextColor);
+        if(m_page>0) _out(m_FillColor);
+    }
+#line 721 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetFillColor (unsigned char r, unsigned char g, unsigned char b)
+#line 722 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set color for all filling operations
+        m_FillColor_rgb = {r,g,b,0};
+        pdf_sprintf(m_FillColor, "%.3f %.3f %.3f rg", r/255.0, g/255.0, b/255.0);
+        m_ColorFlag = (m_FillColor != m_TextColor);
+        if(m_page>0) _out(m_FillColor);
+    }
+#line 738 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetTextColor (unsigned char r)
+#line 739 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set color for text
+        m_TextColor_rgb = {r,r,r,0};
+        pdf_sprintf(m_TextColor, "%.3f g", r/255.0);
+        m_ColorFlag = (m_FillColor != m_TextColor);
+    }
+#line 746 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetTextColor (unsigned char r, unsigned char g, unsigned char b)
+#line 747 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set color for text
+        m_TextColor_rgb = {r,g,b,0};
+        pdf_sprintf(m_TextColor, "%.3f %.3f %.3f rg", r/255.0, g/255.0, b/255.0);
+        m_ColorFlag = (m_FillColor != m_TextColor);
+    }
+#line 766 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetAlpha (pdf_float_t alpha, char const * bm)
+#line 767 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // set alpha for stroking (CA) and non-stroking (ca) operations
+        st_alpha_t gs;
+        gs.alpha = alpha;
+        gs.bm = bm ? bm : "Normal";
+        m_extgstates.push_back(gs);
+        _outfmt(true, "/GS%d gs", m_extgstates.size());
+    }
+#line 776 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+pdf_float_t FPDF::GetStringWidth (char const * s)
+#line 777 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Get width of a string in the current font
+        font_width_t *cw = m_CurrentFont->font.cw;
+        pdf_float_t w = 0.0;
+        if(s)
+        {
+            while(*s)
+            {
+                w += cw[(unsigned char)*s++];
+            }
+        }
+        return w*m_FontSize/1000.0;
+    }
+#line 796 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetLineWidth (pdf_float_t width)
+#line 797 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set line width
+        m_LineWidth = width;
+        if(m_page>0) _outfmt(true, "%.2f w", width*m_k);
+    }
+#line 803 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetDash (pdf_float_t black, pdf_float_t white)
+#line 804 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        if(black >= 0.0f && white >= 0.0f)
+            _outfmt(true, "[%.3f %.3f] 0 d", black*m_k, white*m_k);
+        else
+            _out("[] 0 d");
+    }
+#line 811 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Line (pdf_float_t x1, pdf_float_t y1, pdf_float_t x2, pdf_float_t y2)
+#line 812 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Draw a line
+        _outfmt(true, "%.2f %.2f m %.2f %.2f l S", x1*m_k,(m_h-y1)*m_k,x2*m_k,(m_h-y2)*m_k);
+    }
+#line 817 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Rect (pdf_float_t x, pdf_float_t y, pdf_float_t w, pdf_float_t h, char const * style)
+#line 818 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Draw a rectangle
+        const char *op = "S";
+        if(style)
+        {
+            if(strcasecmp(style, "F") == 0) op = "f";
+            else if( (strcasecmp(style, "FD") == 0) ||
+                     (strcasecmp(style, "DF") == 0) ) op = "B";
+        }
+        _outfmt(true, "%.2f %.2f %.2f %.2f re %s", x*m_k,(m_h-y)*m_k,w*m_k,-h*m_k, op);
+    }
+#line 830 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::AddFont (char const * afamily, char const * astyle, char const * afile)
+#line 831 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Add a TrueType, OpenType or Type1 font
+        std::string family, style;
+        if(afamily && afamily[0])
+        {
+            family = afamily;
+            _str_tolower(family);
+        }
+        else
+        {
+            family = m_FontFamily;
+        }
+        if(astyle && astyle[0])
+        {
+            style = astyle;
+            _str_tolower(style);
+        }
+
+        if(family=="arial") family = "helvetica";
+        if(style=="ib") style = "bi";
+        std::string fontkey = family + style;
+        font_map_t::iterator iter = m_fonts.find(fontkey);
+        if(iter != m_fonts.end()) return; //already inserted
+
+        st_pdf_font_base *font;
+        if(fontkey == "helveticai") font = new pdf_font_HelveticaOblique();
+        else if(fontkey == "helveticab") font = new pdf_font_HelveticaBold();
+        else if(fontkey == "helveticabi") font = new pdf_font_HelveticaBoldOblique();
+        else if(fontkey == "times") font = new pdf_font_Times();
+        else if(fontkey == "timesi") font = new pdf_font_TimesOblique();
+        else if(fontkey == "timesb") font = new pdf_font_TimesBold();
+        else if(fontkey == "timesbi") font = new pdf_font_TimesBoldOblique();
+        else if(fontkey == "courier") font = new pdf_font_Courier();
+        else if(fontkey == "courieri") font = new pdf_font_CourierOblique();
+        else if(fontkey == "courierb") font = new pdf_font_CourierBold();
+        else if(fontkey == "courierbi") font = new pdf_font_CourierBoldOblique();
+        else if(fontkey == "symbol") font = new pdf_font_Symbol();
+        else if(fontkey == "zapfdingbats") font = new pdf_font_ZapfDingbats();
+        else font = new pdf_font_Helvetica();
+        m_fonts[fontkey] = font;
+        font->i = m_fonts.size();
+#if 0
+        if(m_fonts.find(fontkey) == -1) return;
+        st_pdf_font info = _loadfont(file);
+        info.i = m_fonts.size()+1;
+        if(!empty(info["diff"]))
+        {
+            // Search existing encodings
+            n = array_search(info["diff"],m_diffs);
+            if(!n)
+            {
+                n = count(m_diffs)+1;
+                m_diffs[n] = info["diff"];
+            }
+            info["diffn"] = n;
+        }
+        if(!empty(info["file"]))
+        {
+            // Embedded font
+            if(info["type"]=="TrueType")
+                m_FontFiles[info["file"]] = array("length1"=>info["originalsize"]);
+            else
+                m_FontFiles[info["file"]] = array("length1"=>info["size1"], "length2"=>info["size2"]);
+        }
+        m_fonts[fontkey] = info;
+#endif
+    }
+#line 904 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::GetFontSettings (font_settings_st & fs)
+#line 904 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                                              {
+        fs.family = m_FontFamily;
+        fs.style = m_FontStyle;
+        fs.size = m_FontSizePt;
+    }
+#line 910 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetFontSettings (font_settings_st & fs)
+#line 910 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                                              {
+        SetFont(fs.family.c_str(), fs.style.c_str(), fs.size);
+    }
+#line 914 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetFont (char const * afamily, char const * astyle, pdf_float_t size)
+#line 915 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Select a font; size given in points
+        std::string family, style;
+        if(afamily && afamily[0])
+        {
+            family = afamily;
+            _str_tolower(family);
+            if(family=="arial") family = "helvetica";
+        }
+        else
+        {
+            family = m_FontFamily;
+        }
+        if(astyle && astyle[0])
+        {
+            style = astyle;
+            _str_tolower(style);
+        }
+
+        size_t found = style.find("u");
+        if(found != std::string::npos )
+        {
+            m_underline = true;
+            style.erase(found, 1);
+        }
+        else
+            m_underline = false;
+        if(style=="ib") style = "bi";
+        if(size==0) size = m_FontSizePt;
+        // Test if font is already selected
+        if(m_FontFamily==family && m_FontStyle==style && m_FontSizePt==size)
+            return;
+        // Test if font is already loaded
+        std::string fontkey = family + style;
+        font_map_t::iterator iter = m_fonts.find(fontkey);
+        if(iter == m_fonts.end())
+        {
+            // Test if one of the core fonts
+            if(isPdfFontCore(family.c_str()))
+            {
+                if(family=="symbol" || family=="zapfdingbats") style.clear();
+                fontkey = family + style;
+                iter = m_fonts.find(fontkey);
+                if(iter == m_fonts.end()) AddFont(family.c_str(),style.c_str());
+            }
+            else
+                Error("Undefined font: %s %s", family.c_str(), style.c_str());
+        }
+        // Select it
+        m_FontFamily = family;
+        m_FontStyle = style;
+        m_FontSizePt = size;
+        m_FontSize = size/m_k;
+        m_CurrentFont = m_fonts[fontkey];
+        if(m_page>0)
+            _outfmt(true, "BT /F%d %.2f Tf ET", m_CurrentFont->i, m_FontSizePt);
+    }
+#line 973 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetFontSize (pdf_float_t size)
+#line 974 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set font size in points
+        if(m_FontSizePt==size) return;
+        m_FontSizePt = size;
+        m_FontSize = size/m_k;
+        if(m_page>0)
+            _outfmt(true, "BT /F%d %.2f Tf ET", m_CurrentFont->i, m_FontSizePt);
+    }
+#line 988 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+int FPDF::AddLink ()
+#line 989 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Create a new internal link
+        int n = m_links.size();
+        st_link link = {0,0};
+        m_links.push_back(link);
+        return n;
+    }
+#line 997 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetLink (int link, pdf_float_t y, int page)
+#line 998 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set destination of internal link
+        st_link &nlink = m_links[link];
+        if(y==-1) nlink.to = m_y;
+        if(page==-1) page = m_page;
+        nlink.from = page;
+    }
+#line 1006 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Link (pdf_float_t x, pdf_float_t y, pdf_float_t w, pdf_float_t h, int link)
+#line 1007 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Put a link on the page
+        st_page_link pl;
+        pl.x = x*m_k;
+        pl.y = m_hPt-y*m_k;
+        pl.w = w*m_k;
+        pl.h = h*m_k;
+        pl.link = link;
+        m_PageLinks[m_page] = pl;
+    }
+#line 1019 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_TextBase (std::string & result, pdf_float_t x, pdf_float_t y, char const * txt)
+#line 1020 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Output a string
+        //because the format buffer is limited
+        //we send the string separated from format
+        if(m_ColorFlag)
+        {
+            result += "q " + m_TextColor + " ";
+        }
+        pdf_sprintf_append(result, "BT %.2f %.2f Td (", x, y);
+        result += _escape(txt);
+        result += ") Tj ET";
+        if(m_underline && txt)
+        {
+            result += " " + _dounderline(x, y, txt);
+        }
+        if(m_ColorFlag) result += " Q";
+    }
+#line 1040 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Rotate (pdf_float_t angle, pdf_float_t x, pdf_float_t y)
+#line 1041 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        if(x==-1) x=m_x;
+        if(y==-1) y=m_y;
+        if(m_angle!=0) _out("Q");
+        m_angle=angle;
+        if(angle!=0)
+        {
+            angle*=M_PI/180.0;
+            pdf_float_t c=cos(angle);
+            pdf_float_t s=sin(angle);
+            pdf_float_t cx=x*m_k;
+            pdf_float_t cy=(m_h-y)*m_k;
+            _outfmt(true, "q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm",
+                    c,s,-s,c,cx,cy,-cx,-cy);
+        }
+    }
+#line 1058 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::RotatedText (pdf_float_t x, pdf_float_t y, char const * txt, pdf_float_t angle)
+#line 1059 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        //Text rotated around its origin
+        Rotate(angle,x,y);
+        Text(x,y,txt);
+        Rotate(0);
+    }
+#line 1071 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::ClippingText (pdf_float_t x, pdf_float_t y, char const * txt, bool outline)
+#line 1072 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        int op= outline ? 5 : 7;
+        _outfmt(false, "q BT %.2f %.2f Td %d Tr (", x*m_k, (m_h-y)*m_k, op);
+        _out(_escape(txt), false);
+        _out(") Tj ET");
+    }
+#line 1079 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Text (pdf_float_t x, pdf_float_t y, char const * txt)
+#line 1080 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        std::string result;
+        _TextBase(result, x*m_k, (m_h-y)*m_k, txt);
+        _out(result);
+    }
+#line 1086 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::TextShadow (pdf_float_t x, pdf_float_t y, char const * txt, pdf_float_t displacement)
+#line 1088 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        pdf_color_t saved_color = m_TextColor_rgb;
+        SetTextColor(200,200,200);
+        Text(x+displacement, y+displacement, txt);
+        SetTextColor(saved_color);
+        Text(x, y, txt);
+    }
+#line 1096 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+bool FPDF::AcceptPageBreak ()
+#line 1097 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Accept automatic page break or not
+        return m_AutoPageBreak;
+    }
+#line 1102 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Cell (pdf_float_t w, pdf_float_t h, char const * txt, char const * border, int ln, char align, bool fill, int link)
+#line 1104 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Output a cell
+        std::string s;
+        pdf_float_t k = m_k;
+        if(m_y+h > m_PageBreakTrigger && !m_InHeader && !m_InFooter && AcceptPageBreak())
+        {
+            // Automatic page break
+            pdf_float_t x = m_x;
+            pdf_float_t ws = m_ws;
+            if(ws>0)
+            {
+                m_ws = 0;
+                _out("0 Tw");
+            }
+            AddPage(m_CurOrientation, &m_CurPageSize);
+            m_x = x + m_xDelta;
+            if(ws>0)
+            {
+                m_ws = ws;
+                _outfmt(true, "%.3f Tw", ws*k);
+            }
+        }
+        if(w==0)
+            w = m_w-m_rMargin-m_x;
+
+        if(fill || (border && border[0]=='1'))
+        {
+            pdf_sprintf(s, "%.2f %.2f %.2f %.2f re %s ", m_x*k,(m_h-m_y)*k,w*k,-h*k,
+                    fill ? ((border && border[0]=='1') ? "B" : "f") : "S");
+        }
+        if(border)
+        {
+            pdf_float_t x = m_x;
+            pdf_float_t y = m_y;
+            if(strchr(border,'L'))
+                pdf_sprintf_append(s, "%.2f %.2f m %.2f %.2f l S ",x*k,(m_h-y)*k,x*k,(m_h-(y+h))*k);
+            if(strchr(border,'T'))
+                pdf_sprintf_append(s, "%.2f %.2f m %.2f %.2f l S ",x*k,(m_h-y)*k,(x+w)*k,(m_h-y)*k);
+            if(strchr(border,'R'))
+                pdf_sprintf_append(s, "%.2f %.2f m %.2f %.2f l S ",(x+w)*k,(m_h-y)*k,(x+w)*k,(m_h-(y+h))*k);
+            if(strchr(border,'B'))
+                pdf_sprintf_append(s, "%.2f %.2f m %.2f %.2f l S ",x*k,(m_h-(y+h))*k,(x+w)*k,(m_h-(y+h))*k);
+        }
+        if(txt)
+        {
+            pdf_float_t dx;
+            pdf_float_t txt_width = GetStringWidth(txt);
+            if(align=='R')
+                dx = w-m_cMargin-txt_width;
+            else if(align=='C')
+                dx = (w-txt_width)/2;
+            else
+                dx = m_cMargin;
+
+            _TextBase(s, (m_x+dx)*k, (m_h-(m_y+.5*h+.3*m_FontSize))*k, txt);
+
+            if(link)
+                Link(m_x+dx, m_y+.5*h-.5*m_FontSize, txt_width, m_FontSize, link);
+        }
+        if(!s.empty()) _out(s);
+        m_lasth = h;
+        if(ln>0)
+        {
+            // Go to next line
+            m_y += h;
+            if(ln==1) m_x = m_lMargin;
+        }
+        else m_x += w;
+    }
+#line 1180 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::MultiCell (pdf_float_t w, pdf_float_t h, char const * txt, char const * border, char align, bool fill)
+#line 1182 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Output text with automatic or explicit line breaks
+        font_width_t *cw = m_CurrentFont->font.cw;
+        if(w==0) w = m_w-m_rMargin-m_x;
+        pdf_float_t wmax = (w-2*m_cMargin)*1000.0/m_FontSize;
+        std::string stmp, s = txt ? txt : "";
+        _erasestrch(s, '\r');
+        int nb = s.size();
+        if(nb>0 && s[nb-1]=='\n') --nb;
+        std::string b, b2;
+        if(border)
+        {
+            if(border[0]=='1')
+            {
+                border = "LTRB";
+                b = "LRT";
+                b2 = "LR";
+            }
+            else
+            {
+                if(strchr(border,'L')) b2 += "L";
+                if(strchr(border,'R')) b2 += "R";
+                b = strchr(border,'T') ? b2+"T" : b2;
+            }
+        }
+        int sep = -1;
+        int i = 0;
+        int j = 0;
+        int l = 0;
+        int ns = 0;
+        int nl = 1;
+        int ls = 0;
+        while(i<nb)
+        {
+            // Get next character
+            unsigned char c = (unsigned char)s[i];
+            if(c=='\n')
+            {
+                // Explicit line break
+                if(m_ws>0)
+                {
+                    m_ws = 0;
+                    _out("0 Tw");
+                }
+                stmp = s.substr(j, i-j);
+                Cell(w,h,stmp,b.c_str(),2,align,fill);
+                ++i;
+                sep = -1;
+                j = i;
+                l = 0;
+                ns = 0;
+                ++nl;
+                if(border && nl==2)	b = b2;
+                continue;
+            }
+            if(c==' ')
+            {
+                sep = i;
+                ls = l;
+                ++ns;
+            }
+            l += cw[c];
+            if(l>wmax)
+            {
+                // Automatic line break
+                if(sep==-1)
+                {
+                    if(i==j) ++i;
+                    if(m_ws>0)
+                    {
+                        m_ws = 0;
+                        _out("0 Tw");
+                    }
+                    stmp = s.substr(j, i-j);
+                    Cell(w,h,stmp,b.c_str(),2,align,fill);
+                }
+                else
+                {
+                    if(align=='J')
+                    {
+                        m_ws = (ns>1) ? (wmax-ls)/1000.0*m_FontSize/(ns-1) : 0;
+                        //printf("%d %f %f %d %f\n", ns, m_ws, wmax, ls, m_FontSize);
+                        _outfmt(true, "%.3f Tw",m_ws*m_k);
+                    }
+                    stmp = s.substr(j, sep-j);
+                    Cell(w,h,stmp,b.c_str(),2,align,fill);
+                    i = sep+1;
+                }
+                sep = -1;
+                j = i;
+                l = 0;
+                ns = 0;
+                ++nl;
+                if(border && nl==2)
+                    b = b2;
+            }
+            else
+                ++i;
+        }
+        // Last chunk
+        if(m_ws>0)
+        {
+            m_ws = 0;
+            _out("0 Tw");
+        }
+        if(border && strchr(border,'B'))
+            b += "B";
+        stmp = s.substr(j, i-j);
+        Cell(w,h,stmp,b.c_str(),2,align,fill);
+        m_x = m_lMargin;
+    }
+#line 1301 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+int FPDF::CalcLines (pdf_float_t w, char const * txt)
+#line 1302 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        //Computes the number of lines a MultiCell of width w will take
+        font_width_t *cw = m_CurrentFont->font.cw;
+        if(w==0) w = m_w-m_rMargin-m_x;
+        pdf_float_t wmax = (w-2*m_cMargin)*1000.0/m_FontSize;
+        std::string stmp, s = txt ? txt : "";
+        _erasestrch(s, '\r');
+        int nb = s.size();
+        if(nb>0 && s[nb-1]=='\n') --nb;
+
+        int sep = -1;
+        int i = 0;
+        int j = 0;
+        int l = 0;
+        int nl = 1;
+        while(i<nb)
+        {
+            // Get next character
+            unsigned char c = (unsigned char)s[i];
+            if(c == '\n')
+            {
+                ++i;
+                sep = -1;
+                j = i;
+                l = 0;
+                ++nl;
+                continue;
+            }
+            if(c == ' ') sep=i;
+            l += cw[c];
+            if(l > wmax)
+            {
+                if(sep == -1)
+                {
+                    if(i == j) ++i;
+                }
+                else i = sep+1;
+                sep = -1;
+                j = i;
+                l = 0;
+                ++nl;
+            }
+            else
+                ++i;
+        }
+        return nl;
+    }
+#line 1351 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::MultiCellBlt (pdf_float_t w, pdf_float_t h, char const * blt, char const * txt, char const * border, char align, bool fill)
+#line 1354 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        //Get bullet width including margins
+        pdf_float_t blt_width = GetStringWidth(blt)+m_cMargin*2;
+
+        //Save x
+        pdf_float_t bak_x = m_x;
+
+        //Output bullet
+        Cell(blt_width, h, blt,0,' ', fill);
+
+        //Output text
+        MultiCell(w-blt_width, h, txt, border, align, fill);
+
+        //Restore x
+        m_x = bak_x;
+    }
+#line 1371 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::ClippingRect (pdf_float_t x, pdf_float_t y, pdf_float_t w, pdf_float_t h, bool outline)
+#line 1372 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        char op=outline ? 'S' : 'n';
+        _outfmt(true, "q %.2f %.2f %.2f %.2f re W %c",
+            x*m_k, (m_h-y)*m_k, w*m_k,-h*m_k, op);
+    }
+#line 1378 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::UnsetClipping ()
+#line 1379 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        _out("Q");
+    }
+#line 1383 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::ClippedCell (pdf_float_t w, pdf_float_t h, char const * txt, char const * border, int ln, char align, bool fill, int link)
+#line 1385 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        if(border || fill || m_y+h>m_PageBreakTrigger)
+        {
+            Cell(w,h,0,border,0,' ',fill);
+            m_x-=w;
+        }
+        ClippingRect(m_x,m_y,w,h);
+        Cell(w,h,txt,0,ln,align,false,link);
+        UnsetClipping();
+    }
+#line 1397 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::CellFit (pdf_float_t w, pdf_float_t h, char const * txt, char const * border, int ln, char align, bool fill, int link, bool scale, bool force)
+#line 1400 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        //Get string width
+        pdf_float_t str_width=GetStringWidth(txt);
+
+        //Calculate ratio to fit cell
+        if(w==0.0f) w = m_w-m_rMargin-m_x;
+        pdf_float_t ratio = (w-m_cMargin*2)/str_width;
+
+        bool fit = (ratio < 1 || (ratio > 1 && force));
+        if (fit)
+        {
+            if (scale)
+            {
+                //Calculate horizontal scaling
+                pdf_float_t horiz_scale=ratio*100.0;
+                //Set horizontal scaling
+                _outfmt(true, "BT %.2f Tz ET", horiz_scale);
+            }
+            else
+            {
+                //Calculate character spacing in points
+                // TODO (mingo2#1#): UTF-8 strlen
+                int txt_size = txt ? strlen(txt) : 0;
+                pdf_float_t char_space=(w-m_cMargin*2-str_width)/std::max(txt_size-1,1)*m_k;
+                //Set character spacing
+                _outfmt(true, "BT %.2f Tc ET", char_space);
+            }
+            //Override user alignment (since text will fill up cell)
+            align=' ';
+        }
+
+        //Pass on to Cell method
+        Cell(w,h,txt,border,ln,align,fill,link);
+
+        //Reset character spacing/horizontal scaling
+        if (fit)
+        {
+            _out("BT ", false);
+            _out(scale ? "100 Tz" : "0 Tc", false);
+            _out(" ET");
+        }
+    }
+#line 1516 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Write (pdf_float_t h, char const * txt, int link)
+#line 1517 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Output text in flowing mode
+        font_width_t *cw = m_CurrentFont->font.cw;
+        pdf_float_t w = m_w-m_rMargin-m_x;
+        pdf_float_t wmax = (w-2*m_cMargin)*1000.0/m_FontSize;
+        std::string stmp, s = txt ? txt : "";
+        _erasestrch(s, '\r');
+        int nb = s.size();
+        int sep = -1;
+        int i = 0;
+        int j = 0;
+        int l = 0;
+        int nl = 1;
+        while(i<nb)
+        {
+            // Get next character
+            unsigned char c = (unsigned char)s[i];
+            if(c=='\n')
+            {
+                // Explicit line break
+                stmp = s.substr(j, i-j);
+                Cell(w,h,stmp,0,2,' ',0,link);
+                i++;
+                sep = -1;
+                j = i;
+                l = 0;
+                if(nl==1)
+                {
+                    m_x = m_lMargin;
+                    w = m_w-m_rMargin-m_x;
+                    wmax = (w-2*m_cMargin)*1000.0/m_FontSize;
+                }
+                nl++;
+                continue;
+            }
+            if(c==' ') sep = i;
+            l += cw[c];
+            if(l>wmax)
+            {
+                // Automatic line break
+                if(sep==-1)
+                {
+                    if(m_x > m_lMargin)
+                    {
+                        // Move to next line
+                        m_x = m_lMargin;
+                        m_y += h;
+                        w = m_w-m_rMargin-m_x;
+                        wmax = (w-2*m_cMargin)*1000.0/m_FontSize;
+                        i++;
+                        nl++;
+                        continue;
+                    }
+                    if(i==j) i++;
+                    stmp = s.substr(j, i-j);
+                    Cell(w,h,stmp,0,2,' ',0,link);
+                }
+                else
+                {
+                    stmp = s.substr(j, sep-j);
+                    Cell(w,h,stmp,0,2,' ',0,link);
+                    i = sep+1;
+                }
+                sep = -1;
+                j = i;
+                l = 0;
+                if(nl==1)
+                {
+                    m_x = m_lMargin;
+                    w = m_w-m_rMargin-m_x;
+                    wmax = (w-2*m_cMargin)*1000.0/m_FontSize;
+                }
+                nl++;
+            }
+            else
+                i++;
+        }
+        // Last chunk
+        if(i!=j)
+        {
+            stmp = s.substr(j, j);
+            Cell(l/1000.0*m_FontSize,h,stmp,0,0,' ',0,link);
+        }
+    }
+#line 1602 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Ln (pdf_float_t h)
+#line 1603 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Line feed; default value is last cell height
+        m_x = m_lMargin;
+        if(h==0.0) m_y += m_lasth;
+        else m_y += h;
+    }
+#line 1612 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Image (char const * image_name, unsigned char const * image_blob, size_t blob_size, pdf_float_t x, pdf_float_t y, pdf_float_t w, pdf_float_t h, char const * atype, int link)
+#line 1617 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        st_image info;
+        // Put an image on the page
+        if(!image_name) Error("Image name is null !");
+        if(m_images.find(image_name) == m_images.end())
+        {
+            // First use of this image, get info
+            std::string type;
+            if(atype) type = atype;
+            if(type.empty())
+            {
+                if(image_blob)
+                    Error("Image type was not specified: %s", image_name);
+                //else assume image_name is a filename
+                const char *pos = strrchr(image_name,'.');
+                if(!pos)
+                    Error("Image file has no extension and no type was specified: %s", image_name);
+                type = pos+1;
+            }
+            _str_tolower(type);
+            if(type=="jpeg") type = "jpg";
+            if(type == "jpg") {
+                if(image_blob) _parsejpg_blob(info, image_name, image_blob, blob_size);
+                else _parsejpg(info, image_name);
+            }
+            else if(type == "png") {
+                if(image_blob) _parsepng_blob(info, image_name, image_blob, blob_size);
+                else _parsepng(info, image_name);
+            }
+            else Error("Unsupported image type: %s", type.c_str());
+            info.i = m_images.size()+1;
+            m_images[image_name] = info;
+        }
+        else
+            info = m_images[image_name];
+        // Automatic width and height calculation if needed
+        if(w==0.0 && h==0.0)
+        {
+            // Put image at 96 dpi
+            w = -96;
+            h = -96;
+        }
+        else
+        {
+        if(w==0) w = h* info.w/info.h;
+        else if(w<0)	w = - info.w*72.0/w/m_k;
+        if(h==0) h = w* info.h/info.w;
+        else if(h<0) h = - info.h*72.0/h/m_k;
+        }
+
+        pdf_float_t _y, _x;
+        // Flowing mode
+        if(y==-1)
+        {
+            if(m_y+h>m_PageBreakTrigger && !m_InHeader && !m_InFooter && AcceptPageBreak())
+            {
+                // Automatic page break
+                pdf_float_t x2 = m_x;
+                AddPage(m_CurOrientation, &m_CurPageSize);
+                m_x = x2;
+            }
+            _y = m_y;
+            m_y += h;
+        }
+        else _y = y;
+
+        if(x==-1) _x = m_x;
+        else _x = x;
+        _outfmt(true, "q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q",w*m_k,h*m_k,_x*m_k,(m_h-(_y+h))*m_k,info.i);
+        if(link) Link(_x,_y,w,h,link);
+    }
+#line 1689 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Image (char const * file, pdf_float_t x, pdf_float_t y, pdf_float_t w, pdf_float_t h, char const * atype, int link)
+#line 1692 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        Image(file, 0, 0, x, y, w, h, atype, link);
+    }
+#line 1702 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetX (pdf_float_t x)
+#line 1703 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set x position
+        if(x>=0) m_x = x;
+        else m_x = m_w+x;
+    }
+#line 1715 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::SetY (pdf_float_t y)
+#line 1716 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Set y position and reset x
+        m_x = m_lMargin;
+        if(y>=0) m_y = y;
+        else m_y = m_h+y;
+    }
+#line 1742 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+std::string FPDF::Output (char const * name, char dest)
+#line 1743 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Output PDF to some destination
+        if(m_state<3) Close();
+        if(dest==' ')
+        {
+            if(!name)
+            {
+                name = "doc.pdf";
+                dest = 'I';
+            }
+            else
+                dest = 'F';
+        }
+        switch(dest)
+        {
+#if 0
+        case 'I':
+            // Send to standard output
+            _checkoutput();
+            if(PHP_SAPI!="cli")
+            {
+                // We send to a browser
+                header("Content-Type: application/pdf");
+                header("Content-Disposition: inline; filename="".name.""");
+                header("Cache-Control: private, max-age=0, must-revalidate");
+                header("Pragma: public");
+            }
+            echo m_buffer;
+            break;
+        case 'D':
+            // Download file
+            _checkoutput();
+            header("Content-Type: application/x-download");
+            header("Content-Disposition: attachment; filename="".name.""");
+            header("Cache-Control: private, max-age=0, must-revalidate");
+            header("Pragma: public");
+            echo m_buffer;
+            break;
+#endif
+        case 'F':
+        {
+            // Save to local file
+            FILE *f = fopen(name,"wb");
+            if(!f)
+                Error("Unable to create output file: %s", name);
+            fwrite(m_buffer.c_str(), m_buffer.size(), 1, f);
+            fclose(f);
+        }
+        break;
+        case 'S':
+            // Return as a string
+            return m_buffer;
+        default:
+            Error("Incorrect output destination: %c", dest);
+        }
+        return "";
+    }
+#line 1801 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::RoundedRect (pdf_float_t x, pdf_float_t y, pdf_float_t w, pdf_float_t h, pdf_float_t r, char const * style)
+#line 1803 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        pdf_float_t k = m_k;
+        pdf_float_t hp = m_h;
+        pdf_float_t MyArc = 4.0/3.0 * (sqrt(2) - 1);
+        _outfmt(true, "%.2f %.2f m",(x+r)*k,(hp-y)*k);
+        pdf_float_t xc = x+w-r;
+        pdf_float_t yc = y+r;
+        _outfmt(true, "%.2f %.2f l", xc*k,(hp-y)*k);
+
+        _Arc(xc + r*MyArc, yc - r, xc + r, yc - r*MyArc, xc + r, yc);
+        xc = x+w-r;
+        yc = y+h-r;
+        _outfmt(true, "%.2f %.2f l",(x+w)*m_k,(hp-yc)*m_k);
+        _Arc(xc + r, yc + r*MyArc, xc + r*MyArc, yc + r, xc, yc + r);
+        xc = x+r;
+        yc = y+h-r;
+        _outfmt(true, "%.2f %.2f l",xc*m_k,(hp-(y+h))*m_k);
+        _Arc(xc - r*MyArc, yc + r, xc - r, yc + r*MyArc, xc - r, yc);
+        xc = x+r;
+        yc = y+r;
+        _outfmt(true, "%.2F %.2F l",(x)*m_k,(hp-yc)*m_k);
+        _Arc(xc - r, yc - r*MyArc, xc - r*MyArc, yc - r, xc, yc - r);
+        std::string str_style = style ? style : "";
+        if(str_style=="F") _out("f");
+        else if(str_style=="FD" || str_style=="DF") _out("B");
+        else _out("S");
+    }
+#line 1831 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Circle (pdf_float_t x, pdf_float_t y, pdf_float_t r, char const * style)
+#line 1832 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        Ellipse(x,y,r,r,style);
+    }
+#line 1836 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::Ellipse (pdf_float_t x, pdf_float_t y, pdf_float_t rx, pdf_float_t ry, char const * style)
+#line 1838 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        const char *op = "S";
+        std::string str_style = style ? style : "";
+        if(str_style=="F") op ="f";
+        else if(str_style=="FD" || str_style=="DF") op ="B";
+        pdf_float_t tmp = 4.0/3.0*(sqrt(2)-1);
+        pdf_float_t lx=tmp*rx;
+        pdf_float_t ly=tmp*ry;
+        _outfmt(true, "%.2f %.2f m %.2f %.2f %.2f %.2f %.2f %.2f c",
+                (x+rx)*m_k,(m_h-y)*m_k,
+                (x+rx)*m_k,(m_h-(y-ly))*m_k,
+                (x+lx)*m_k,(m_h-(y-ry))*m_k,
+                x*m_k,(m_h-(y-ry))*m_k);
+        _outfmt(true, "%.2f %.2f %.2f %.2f %.2f %.2f c",
+                (x-lx)*m_k,(m_h-(y-ry))*m_k,
+                (x-rx)*m_k,(m_h-(y-ly))*m_k,
+                (x-rx)*m_k,(m_h-y)*m_k);
+        _outfmt(true, "%.2f %.2f %.2f %.2f %.2f %.2f c",
+                (x-rx)*m_k,(m_h-(y+ly))*m_k,
+                (x-lx)*m_k,(m_h-(y+ry))*m_k,
+                x*m_k,(m_h-(y+ry))*m_k);
+        _outfmt(true, "%.2f %.2f %.2f %.2f %.2f %.2f c %s",
+                (x+lx)*m_k,(m_h-(y+ry))*m_k,
+                (x+rx)*m_k,(m_h-(y+ly))*m_k,
+                (x+rx)*m_k,(m_h-y)*m_k,
+                op);
+    }
+#line 1866 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::IncludeJS (char const * script)
+#line 1867 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        m_javascript=script;
+    }
+#line 1878 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_Arc (pdf_float_t x1, pdf_float_t y1, pdf_float_t x2, pdf_float_t y2, pdf_float_t x3, pdf_float_t y3)
+#line 1879 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        pdf_float_t h = m_h;
+        _outfmt(true, "%.2f %.2f %.2f %.2f %.2f %.2f c ", x1*m_k,
+                (h-y1)*m_k, x2*m_k, (h-y2)*m_k, x3*m_k, (h-y3)*m_k);
+    }
+#line 1885 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+std::string & FPDF::_erasestrch (std::string & str, char c)
+#line 1886 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        if(!str.empty())
+        {
+            size_t size = str.size();
+            //int used intentionally for the case of 0nt char should be erased
+            for(size_t i=0; i<size; ++i)
+            {
+                if(str.at(i) == c)
+                {
+                    str.erase(i, 1);
+                    --size;
+                    --i;
+                }
+            }
+        }
+        return str;
+    }
+#line 1904 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_str_tolower (std::string & str)
+#line 1905 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        for(size_t i=0, size=str.size(); i < size; ++i)
+        {
+            str[i] = tolower(str[i]);
+        }
+    }
+#line 1912 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_dochecks ()
+#line 1913 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {}
+#line 1916 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_checkoutput ()
+#line 1917 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+#if 0
+
+        if(PHP_SAPI!="cli")
+        {
+            if(headers_sent(file,line))
+                Error("Some data has already been output, can't send PDF file (output started at file:line)");
+        }
+        if(ob_get_length())
+        {
+            // The output buffer is not empty
+            if(preg_match("/^(\xEF\xBB\xBF)?\s*/",ob_get_contents()))
+            {
+                // It contains only a UTF-8 BOM and/or whitespace, let"s clean it
+                ob_clean();
+            }
+            else
+                Error("Some data has already been output, can't send PDF file");
+        }
+#endif
+    }
+#line 1939 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+FPDF::st_pagesize & FPDF::_getpagesize (st_pagesize & result, e_page_sizes size)
+#line 1940 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        switch(size)
+        {
+        case e_A3:
+            result.w = 841.89;
+            result.h = 1190.55;
+            break;
+        case e_A5:
+            result.w = 420.94;
+            result.h = 595.28;
+            break;
+        case e_Letter:
+            result.w = 612;
+            result.h = 792;
+            break;
+        case e_Legal:
+            result.w = 612;
+            result.h = 1008;
+            break;
+        default:
+            /*case e_A4:*/
+            result.w = 595.28;
+            result.h = 841.89;
+            break;
+        }
+
+        result.w /= m_k;
+        result.h /=m_k;
+        return result;
+    }
+#line 1971 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_beginpage (e_orientation orientation, st_pagesize * size)
+#line 1972 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        m_page++;
+        m_pages.resize(m_page);
+        m_state = 2;
+        m_x = m_lMargin;
+        m_y = m_tMargin;
+        m_FontFamily = "";
+        // Check page size and orientation
+        if(orientation==e_orientation_none) orientation = m_DefOrientation;
+        st_pagesize *psize;
+        if(!size) psize = &m_DefPageSize;
+        else psize = size;
+        if(orientation!=m_CurOrientation || psize->w != m_CurPageSize.w || psize->h  != m_CurPageSize.h)
+        {
+            // New size or orientation
+            if(orientation==e_orientation_portrait)
+            {
+                m_w = psize->w;
+                m_h = psize->h;
+            }
+            else
+            {
+                m_w = psize->h;
+                m_h = psize->w;
+            }
+            m_wPt = m_w*m_k;
+            m_hPt = m_h*m_k;
+            m_PageBreakTrigger = m_h-m_bMargin;
+            m_CurOrientation = orientation;
+            m_CurPageSize = *psize;
+        }
+        if(orientation != m_DefOrientation || psize->w != m_DefPageSize.w || psize->h != m_DefPageSize.h)
+        {
+            st_pagesize ps;
+            ps.w = m_wPt;
+            ps.h = m_hPt;
+            m_PageSizes[m_page] = ps;
+        }
+
+        if ( m_doubleSided )
+        {
+            if( m_page % 2 == 0 )
+            {
+                m_xDelta=m_outerMargin - m_innerMargin;
+                SetLeftMargin(m_outerMargin);
+                SetRightMargin(m_innerMargin);
+            }
+            else
+            {
+                m_xDelta=m_innerMargin - m_outerMargin;
+                SetLeftMargin(m_innerMargin);
+                SetRightMargin(m_outerMargin);
+            }
+            m_x=m_lMargin;
+            m_y=m_tMargin;
+        }
+    }
+#line 2051 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+std::string FPDF::_escape (std::string const & s)
+#line 2052 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        std::string str = s;
+        if(!str.empty())
+        {
+            size_t size = str.size();
+            for(size_t i=0; i<size; ++i)
+            {
+                switch((unsigned char)str.at(i))
+                {
+                case '\\':
+                case '(':
+                case ')':
+                    str.insert(i, "\\");
+                    ++size;
+                    ++i;
+                    continue;
+                case '\r':
+                    str.erase(i, 1);
+                    --size;
+                    continue;
+                //now a cheap ut82latin
+                case 0xE2: //euro 0xE282AC = \200
+                    if(((unsigned char)str[i+1]) == 0x82 && ((unsigned char)str[i+2]) == 0xAC)
+                    {
+                        str[i] = '\\';
+                        str[i+1] = '2';
+                        str[i+2] = '0';
+                        str.insert(i+3, "0");
+                        size += 1;
+                        i += 3;
+                    }
+                    continue;
+                case 0xC2:
+                    str.erase(i, 1);
+                    --size;
+                    continue;
+                case 0xC3:
+                    str.erase(i, 1);
+                    str[i] += 64;
+                    --size;
+                    --i;
+                    continue;
+                }
+            }
+        }
+        return str;
+    }
+#line 2100 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_textstring (std::string & result, std::string const & s)
+#line 2101 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Format a text string
+        result = "(" + _escape(s) + ")";
+    }
+#line 2141 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+int FPDF::substr_count (char const * str, char c)
+#line 2142 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        int result = 0;
+        if(str)
+        {
+            while(*str)
+            {
+                if(*str++ == c) result++;
+            }
+        }
+        return result;
+    }
+#line 2154 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+std::string FPDF::_dounderline (pdf_float_t x, pdf_float_t y, char const * txt)
+#line 2155 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Underline text
+        int up = m_CurrentFont->font.up;
+        int ut = m_CurrentFont->font.ut;
+        int w = GetStringWidth(txt)+m_ws*substr_count(txt,' ');
+        pdf_snprintf(m_scratch_buf, sizeof(m_scratch_buf), "%.2f %.2f %.2f %.2f re f",x*m_k,(m_h-(y-up/1000.0*m_FontSize))*m_k,w*m_k,-ut/1000.0*m_FontSizePt);
+        return m_scratch_buf;
+    }
+#line 2169 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+FPDF::blob_stream_t::~ blob_stream_t ()
+#line 2169 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                                {}
+#line 2176 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+FPDF::blob_stream_memory_t::blob_stream_memory_t (unsigned char const * ablob, size_t asize)
+#line 2176 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                                                                      {
+            blob = ablob;
+            size = asize;
+            offset = 0;
+        }
+#line 2181 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+bool FPDF::blob_stream_memory_t::eof ()
+#line 2181 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                  {
+            return offset == size;
+        }
+#line 2184 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+size_t FPDF::blob_stream_memory_t::tell ()
+#line 2184 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                     {
+            return offset;
+        }
+#line 2188 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+size_t FPDF::blob_stream_memory_t::read (void * dest, size_t num_read)
+#line 2189 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+        {
+          if (offset + num_read > size)
+            num_read = size - offset;
+
+          memcpy ((char *)dest, blob + offset, num_read);
+
+          offset += num_read;
+
+          return num_read;
+        }
+#line 2200 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::blob_stream_memory_t::seek (size_t to_offset, int whence)
+#line 2201 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+        {
+          size_t npos;
+
+          switch (whence) {
+            case SEEK_SET:
+              npos = to_offset;
+              break;
+
+            case SEEK_CUR:
+              npos = offset + to_offset;
+              break;
+
+            case SEEK_END:
+              npos = size;
+              break;
+          }
+
+          offset = npos > size ? size : npos;
+        }
+#line 2224 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+FPDF::blob_stream_file_t::blob_stream_file_t (FILE * afp)
+#line 2224 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                                     {
+            fp = afp;
+        }
+#line 2227 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+FPDF::blob_stream_file_t::~ blob_stream_file_t ()
+#line 2227 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                             {
+            if(fp) fclose(fp);
+        }
+#line 2230 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+bool FPDF::blob_stream_file_t::eof ()
+#line 2230 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                  {
+            return feof(fp);
+        }
+#line 2233 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+size_t FPDF::blob_stream_file_t::tell ()
+#line 2233 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                     {
+            return ftell(fp);
+        }
+#line 2237 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+size_t FPDF::blob_stream_file_t::read (void * dest, size_t num_read)
+#line 2238 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+        {
+          return fread(dest, 1, num_read, fp);
+        }
+#line 2242 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::blob_stream_file_t::seek (size_t to_offset, int whence)
+#line 2243 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+        {
+            fseek(fp, to_offset, whence);
+        }
+#line 2273 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_parsejpg (st_image & info, blob_stream_t & fp, char const * image_name)
+#line 2274 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        bool isValid = false;
+        info.cs.clear();
+        info.pal.clear();
+        info.trns.clear();
+        info.data.clear();
+
+        std::string buf;
+        _readstream(buf,fp,3);
+        if (buf != "\xff\xd8\xff")
+            Error("Not a JPG image: %s", image_name);
+
+        // Extract info from a JPEG file
+        unsigned int   marker = M_PSEUDO;
+        unsigned short length, ffRead = 1;
+        unsigned char  bits     = 0;
+        unsigned short height   = 0;
+        unsigned short width    = 0;
+        unsigned char  channels = 0;
+
+
+        bool ready = false;
+        int lastMarker;
+        int commentCorrection;
+        int a;
+        while (!ready)
+        {
+            lastMarker = marker;
+            commentCorrection = 1;
+            a = 0;
+
+            // get marker byte, swallowing possible padding
+            if (lastMarker == M_COM && commentCorrection)
+            {
+                // some software does not count the length bytes of COM section
+                // one company doing so is very much envolved in JPEG... so we accept too
+                // by the way: some of those companies changed their code now...
+                commentCorrection = 2;
+            }
+            else
+            {
+                lastMarker = 0;
+                commentCorrection = 0;
+            }
+            if (ffRead)
+            {
+                a = 1; // already read 0xff in filetype detection
+            }
+            do
+            {
+                _readstream(buf,fp,1);
+                if (fp.eof())
+                {
+                    marker = M_EOI; // we hit EOF
+                    break;
+                }
+                marker = (unsigned char)buf[0];
+                if (lastMarker == M_COM && commentCorrection > 0)
+                {
+                    if (marker != 0xFF)
+                    {
+                        marker = 0xff;
+                        commentCorrection--;
+                    }
+                    else
+                    {
+                        lastMarker = M_PSEUDO; // stop skipping non 0xff for M_COM
+                    }
+                }
+                if (++a > 10)
+                {
+                    // who knows the maxim amount of 0xff? though 7
+                    // but found other implementations
+                    marker = M_EOI;
+                    break;
+                }
+            }
+            while (marker == 0xff);
+
+            if (a < 2)
+            {
+                marker = M_EOI; // at least one 0xff is needed before marker code
+            }
+            if (lastMarker == M_COM && commentCorrection)
+            {
+                marker = M_EOI; // ah illegal: char after COM section not 0xFF
+            }
+
+            ffRead = 0;
+            switch (marker)
+            {
+            case M_SOF0:
+            case M_SOF1:
+            case M_SOF2:
+            case M_SOF3:
+            case M_SOF5:
+            case M_SOF6:
+            case M_SOF7:
+            case M_SOF9:
+            case M_SOF10:
+            case M_SOF11:
+            case M_SOF13:
+            case M_SOF14:
+            case M_SOF15:
+                // handle SOFn block
+                length = (unsigned short)_readshort(fp);
+                _readstream(buf, fp,1);
+                bits = (unsigned char)buf[0];
+                height = (unsigned short)_readshort(fp);
+                width  = (unsigned short)_readshort(fp);
+                _readstream(buf, fp,1);
+                channels = (unsigned char)buf[0];
+                isValid = true;
+                ready = true;
+                break;
+
+            case M_SOS:
+            case M_EOI:
+                isValid = false;
+                ready = true;
+
+            default:
+            {
+                // anything else isn't interesting
+                long pos = (unsigned short) _readshort(fp);
+                pos = pos-2;
+                if (pos)
+                {
+                    fp.seek(pos, SEEK_CUR );
+                }
+            }
+            break;
+            }
+        }
+
+        if (isValid)
+        {
+            if (channels == 3)
+            {
+                info.cs = "DeviceRGB";
+            }
+            else if(channels == 4)
+            {
+                info.cs = "DeviceCMYK";
+            }
+            else
+            {
+                info.cs = "DeviceGray";
+            }
+            info.bpc = bits;
+
+            //Read whole file
+            fp.seek(0, SEEK_END);
+            int fsize = fp.tell();
+            fp.seek(0, SEEK_SET);
+            _readstream(info.data, fp, fsize);
+            info.w  = width;
+            info.h = height;
+            info.f = "DCTDecode";
+            return;
+        }
+        Error("Invalid JPG image: %s", image_name);
+    }
+#line 2438 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_parsejpg (st_image & info, char const * file_name)
+#line 2439 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Extract info from a JPG file
+        FILE *fp = fopen(file_name,"rb");
+
+        if(!fp) Error("Can't open image file: %s", file_name);
+        blob_stream_file_t sf(fp);
+        _parsejpg(info, sf, file_name);
+    }
+#line 2448 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_parsejpg_blob (st_image & info, char const * image_name, unsigned char const * image_blob, size_t blob_size)
+#line 2450 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        if(!image_name) Error("Image name is NULL!");
+        if(!image_blob) Error("Image blob is NULL!");
+        if(!blob_size) Error("Image blob size is zero!");
+        blob_stream_memory_t sm(image_blob, blob_size);
+        _parsejpg(info, sm, image_name);
+    }
+#line 2458 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_parsepng (st_image & info, char const * file_name)
+#line 2459 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Extract info from a PNG file
+        FILE *fp = fopen(file_name,"rb");
+
+        if(!fp) Error("Can't open image file: %s", file_name);
+        blob_stream_file_t sf(fp);
+        _parsepngstream(info, sf, file_name);
+    }
+#line 2469 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_parsepng_blob (st_image & info, char const * image_name, unsigned char const * image_blob, size_t blob_size)
+#line 2471 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        if(!image_name) Error("Image name is NULL!");
+        if(!image_blob) Error("Image blob is NULL!");
+        if(!blob_size) Error("Image blob size is zero!");
+        blob_stream_memory_t sm(image_blob, blob_size);
+        _parsepngstream(info, sm, image_name);
+    }
+#line 2479 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_getGrayImgColorAndalpha (std::string & color, std::string & alpha, std::string & line)
+#line 2479 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                                                                                            {
+        size_t size = line.size();
+        color.reserve(size);
+        alpha.reserve(size);
+        for(size_t i=0; i<size; i+=2){
+            color += line[i];
+            alpha += line[i+1];
+        }
+    }
+#line 2489 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_getRGBImgColorAndalpha (std::string & color, std::string & alpha, std::string & line)
+#line 2489 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+                                                                                           {
+        size_t size = line.size();
+        color.reserve(size);
+        alpha.reserve(size/3);
+        for(size_t i=0; i<size; i+=4){
+            color.append(line.c_str()+i, 3);
+            alpha += line[i+3];
+        }
+    }
+#line 2499 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_parsepngstream (st_image & info, blob_stream_t & fp, char const * image_name)
+#line 2500 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        std::string buf;
+        // Check signature
+        _readstream(buf, fp, 8);
+
+        if(buf != "\x89PNG\x0D\x0A\x1A\x0A")
+            Error("Not a PNG image: %s", image_name);
+
+        // Read header chunk
+        _readstream(buf, fp, 4);
+        _readstream(buf, fp, 4);
+        if(buf != "IHDR") Error("Incorrect PNG image: %s", image_name);
+        info.w = _readint(fp);
+        info.h = _readint(fp);
+        _readstream(buf, fp, 1);
+        info.bpc = buf[0];
+        if(info.bpc>8) Error("16-bit depth not supported: %s", image_name);
+        _readstream(buf, fp, 1);
+        int ct = buf[0];
+        if(ct==0 || ct==4) info.cs = "DeviceGray";
+        else if(ct==2 || ct==6) info.cs = "DeviceRGB";
+        else if(ct==3) info.cs = "Indexed";
+        else Error("Unknown color type: %s", image_name);
+        _readstream(buf, fp, 3);
+        if(buf[0]!=0)
+            Error("Unknown compression method: %s", image_name);
+        if(buf[1]!=0)
+            Error("Unknown filter method: %s", image_name);
+        if(buf[2]!=0)
+            Error("Interlacing not supported: %s", image_name);
+        _readstream(buf,fp,4);
+        pdf_sprintf(info.dp, "/Predictor 15 /Colors %d /BitsPerComponent %d  /Columns %d",
+                (info.cs=="DeviceRGB" ? 3 : 1), (int)info.bpc, (int)info.w);
+
+        // Scan chunks looking for palette, transparency and image data
+        info.pal.clear();
+        info.trns.clear();
+        info.data.clear();
+        int n;
+        do
+        {
+            n = _readint(fp);
+            _readstream(buf, fp, 4);
+            if(buf=="PLTE")
+            {
+                // Read palette
+                _readstream(info.pal, fp,n);
+                _readstream(buf, fp, 4);
+            }
+            else if(buf=="tRNS")
+            {
+                // Read transparency info
+                _readstream(buf,fp,n);
+                if(ct==0)
+                {
+                    info.trns.push_back(buf[1]);
+                }
+                else if(ct==2)
+                {
+                    info.trns.push_back(buf[1]);
+                    info.trns.push_back(buf[3]);
+                    info.trns.push_back(buf[5]);
+                }
+                else
+                {
+                    size_t pos = buf.find('\0');
+                    if(pos!=std::string::npos)
+                        info.trns.push_back(buf[pos]);
+                }
+                _readstream(buf,fp,4);
+            }
+            else if(buf=="IDAT")
+            {
+                // Read image data block
+                info.data += _readstream(buf,fp,n);
+                _readstream(buf, fp, 4);
+            }
+            else if(buf=="IEND")
+                break;
+            else
+                _readstream(buf,fp,n+4);
+        }
+        while(n);
+
+        if(info.cs=="Indexed" && info.pal.empty()) Error("Missing palette in %s", image_name);
+        info.f = "FlateDecode";
+#ifdef PDF_USING_ZLIB
+        if(ct>=4)
+        {
+            // Extract alpha channel
+            std::string data;
+            gzuncompress(data, info.data);
+            std::string color, alpha, line;
+            if(ct==4)
+            {
+                // Gray image
+                int len = 2*info.w;
+                for(int i=0; i<info.h; i++)
+                {
+                    int pos = (1+len)*i;
+                    color.append(data[pos], 1);
+                    alpha.append(data[pos], 1);
+                    line.assign(data.c_str()+pos+1,len);
+                    _getGrayImgColorAndalpha(color, alpha, line);
+                    //color += preg_replace("/(.)./s","1",line);
+                    //alpha += preg_replace("/.(.)/s","1",line);
+                }
+            }
+            else
+            {
+                // RGB image
+                int len = 4*info.w;
+                for(int i=0; i<info.h; i++)
+                {
+                    int pos = (1+len)*i;
+                    color.append(data[pos], 1);
+                    alpha.append(data[pos], 1);
+                    line.assign(data.c_str()+pos+1,len);
+                    _getRGBImgColorAndalpha(color, alpha, line);
+                    //color += preg_replace("/(.{3})./s","1",line);
+                    //alpha += preg_replace("/.{3}(.)/s","1",line);
+                }
+            }
+            gzcompress(info.smask, alpha);
+            data.clear();
+            gzcompress(info.data, color);
+            if(m_PDFVersion < "1.4") m_PDFVersion = "1.4";
+        }
+#endif
+    }
+#line 2631 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+std::string & FPDF::_readstream (std::string & result, blob_stream_t & fp, size_t n)
+#line 2632 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Read n bytes from stream
+        result.resize(n);
+        if(fp.read(&result[0], n) != n) Error("Can't read from stream !");
+        return result;
+    }
+#line 2639 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+int FPDF::_readint (blob_stream_t & fp)
+#line 2640 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Read a 4-byte integer from stream
+        std::string buf;
+        _readstream(buf, fp, 4);
+        int i = 1;
+        char *p = (char *)&i;
+        if (p[0] == 1)  //LITTLE_ENDIAN
+        {
+            unsigned char c0 = buf[0], c1 = buf[1], c2 = buf[2], c3 = buf[3];
+            buf[0] = c3;
+            buf[1] = c2;
+            buf[2] = c1;
+            buf[3] = c0;
+        }
+        //else BIG_ENDIAN
+        return *((int*)&buf[0]);
+    }
+#line 2658 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+int FPDF::_readshort (blob_stream_t & fp)
+#line 2659 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Read a 4-byte integer from stream
+        std::string buf;
+        _readstream(buf, fp, 2);
+        short i = 1;
+        char *p = (char *)&i;
+        if (p[0] == 1)  //LITTLE_ENDIAN
+        {
+            unsigned char c0 = buf[0], c1 = buf[1];
+            buf[0] = c1;
+            buf[1] = c0;
+        }
+        //else BIG_ENDIAN
+        return *((short*)&buf[0]);
+    }
+#line 2675 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_parsegif (std::string & file)
+#line 2676 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+#if 0
+        // Extract info from a GIF file (via PNG conversion)
+        if(!function_exists("imagepng"))
+            Error("GD extension is required for GIF support");
+        if(!function_exists("imagecreatefromgif"))
+            Error("GD has no GIF read support");
+        im = imagecreatefromgif(file);
+        if(!im)
+            Error("Missing or incorrect image file: ".file);
+        imageinterlace(im,0);
+        f = @fopen("php://temp","rb+");
+        if(f)
+        {
+            // Perform conversion in memory
+            ob_start();
+            imagepng(im);
+            data = ob_get_clean();
+            imagedestroy(im);
+            fwrite(f,data);
+            fseek(fp, 0, SEEK_SET);
+            info = _parsepngstream(f,file);
+            fclose(f);
+        }
+        else
+        {
+            // Use temporary file
+            tmp = tempnam(".","gif");
+            if(!tmp)
+                Error("Unable to create a temporary file");
+            if(!imagepng(im,tmp))
+                Error("Error while saving to temporary file");
+            imagedestroy(im);
+            info = _parsepng(tmp);
+            unlink(tmp);
+        }
+        return info;
+#endif
+    }
+#line 2716 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_newobj ()
+#line 2717 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Begin a new object
+        m_n++;
+        m_offsets.push_back(m_buffer.size());
+        _outfmt(true, "%d 0 obj", m_n);
+    }
+#line 2724 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putstream (std::string const & s)
+#line 2725 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        _out("stream");
+        _out(s);
+        _out("endstream");
+    }
+#line 2731 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_out (char const * s, size_t size, bool nl)
+#line 2732 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        // Add a line to the document
+        if(m_state==2)
+        {
+            std::string &str = m_pages[m_page-1];
+            str.append(s, size);
+            if(nl) str += "\n";
+        }
+        else
+        {
+            m_buffer.append(s, size);
+            if(nl) m_buffer += "\n";
+        }
+    }
+#line 2747 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+std::string & FPDF::pdf_sprintf (std::string & s, char const * fmt, ...)
+#line 2748 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        va_list args;
+        va_start( args, fmt );
+        int size = pdf_vsnprintf(m_scratch_buf, sizeof(m_scratch_buf), fmt, args);
+        va_end( args );
+        if(size < 0) Error("Too big string passed to sprintf %d", __LINE__);
+        s = m_scratch_buf;
+        return s;
+    }
+#line 2758 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::pdf_sprintf_append (std::string & s, char const * fmt, ...)
+#line 2759 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        va_list args;
+        va_start( args, fmt );
+        int size = pdf_vsnprintf(m_scratch_buf, sizeof(m_scratch_buf), fmt, args);
+        va_end( args );
+        if(size < 0) Error("Too big string passed to sprintf %d", __LINE__);
+        s += m_scratch_buf;
+    }
+#line 2768 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_outfmt (bool nl, char const * fmt, ...)
+#line 2769 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        va_list args;
+        va_start( args, fmt );
+        int size = pdf_vsnprintf(m_scratch_buf, sizeof(m_scratch_buf), fmt, args);
+        va_end( args );
+        if(size < 0) Error("Too big string passed to sprintf %d", __LINE__);
+        _out(m_scratch_buf, size, nl);
+    }
+#line 2778 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_out (char const * s, bool nl)
+#line 2779 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        _out(s, strlen(s), nl);
+    }
+#line 2783 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_out (std::string const & s, bool nl)
+#line 2784 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        _out(s.c_str(), s.size(), nl);
+    }
+#line 2788 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putpages ()
+#line 2789 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        int nb = m_page;
+        if(!m_AliasNbPages.empty())
+        {
+            // Replace number of pages
+            std::string str;
+            pdf_sprintf(str, "%d", nb);
+            for(int n=0; n<nb; n++)
+            {
+                std::string &page = m_pages[n];
+                for(std::string::size_type loc = page.find(m_AliasNbPages);
+                        loc != std::string::npos; loc = page.find(m_AliasNbPages, loc))
+                {
+                    page.replace(loc, m_AliasNbPages.size(), str, 0, str.size());
+                }
+            }
+        }
+        pdf_float_t wPt, hPt;
+        if(m_DefOrientation==e_orientation_portrait)
+        {
+            wPt = m_DefPageSize.w*m_k;
+            hPt = m_DefPageSize.h*m_k;
+        }
+        else
+        {
+            wPt = m_DefPageSize.h*m_k;
+            hPt = m_DefPageSize.w*m_k;
+        }
+        std::string filter = (m_compress) ? "/Filter /FlateDecode " : "";
+        for(int n=1; n<=nb; n++)
+        {
+            // Page
+            _newobj();
+            _outfmt(true, "<<\n/Type /Page");
+            _outfmt(true, "/Parent 1 0 R");
+            if(m_PageSizes.find(n) != m_PageSizes.end())
+                _outfmt(true, "/MediaBox [0 0 %.2f %.2f]",m_PageSizes[n].w,m_PageSizes[n].h);
+            _outfmt(true, "/Resources 2 0 R");
+            if(m_PageLinks.find(n) != m_PageLinks.end())
+            {
+                // Links
+                std::string annots = "/Annots [";
+#if 0
+                link_map_t::iterator iter = m_PageLinks[n].begin();
+                link_map_t::iterator iend = m_PageLinks[n].end();
+                for(; iter != iend; ++iter)
+                {
+                    st_page_link &pl = *iter->second;
+                    pdf_snprintf(m_scratch_buf, sizeof(m_scratch_buf), "%.2f %.2f %.2f %.2f",pl[0],pl[1],pl[0]+pl[2],pl[1]-pl[3]);
+                    rect = m_scratch_buf;
+                    annots += "<<\n/Type /Annot /Subtype /Link /Rect [" +  rect + "] /Border [0 0 0] ";
+                    if(is_string(pl[4]))
+                        annots += "/A\n<<\n/S /URI /URI " + _3textstring(pl[4]) + "\n>>\n>>\n";
+                    else
+                    {
+                        l = m_links[pl[4]];
+                        int lidx = l[0];
+                        h = m_PageSizes.find([lidx]) != -1 ? m_PageSizes[lidx].h : hPt;
+                        pdf_sprintf_append(annots, "/Dest [%d 0 R /XYZ 0 %.2f null]\n>>\n",1+2*lidx,h-l[1]*m_k);
+                    }
+                }
+#endif
+                _out(annots + "]");
+            }
+            if(m_PDFVersion > "1.3")
+                _outfmt(true, "/Group\n<<\n/Type /Group /S /Transparency /CS /DeviceRGB\n>>");
+            _outfmt(true, "/Contents %d 0 R\n>>", m_n+1);
+            _out("endobj");
+            // Page content
+            std::string zbuf, &p =
+#ifdef PDF_USING_ZLIB
+                (m_compress) ? gzcompress(zbuf, m_pages[n-1]) :
+#endif
+                m_pages[n-1];
+            _newobj();
+            _out("<<");
+            _out(filter, false);
+            _outfmt(true, "/Length %d\n>>", p.size());
+            _putstream(p);
+            _out("endobj");
+        }
+        // Pages root
+        m_offsets[1] = m_buffer.size();
+        _out("1 0 obj");
+        _out("<<\n/Type /Pages");
+        std::string kids = "/Kids [";
+        for(int i=0; i<nb; i++) pdf_sprintf_append(kids, "%d 0 R ",(3+2*i));
+        _out(kids + "]");
+        _outfmt(true, "/Count %d", nb);
+        _outfmt(true, "/MediaBox [0 0 %.2f %.2f]", wPt, hPt);
+        _out(">>");
+        _out("endobj");
+    }
+#line 2883 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putfonts ()
+#line 2884 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+#if 0
+        int nf = m_n;
+        foreach(m_diffs as diff)
+        {
+            // Encodings
+            _newobj();
+            _outfmt(true, "<<\n/Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [".diff."]\n>>");
+            _outfmt(true, "endobj");
+        }
+        foreach(m_FontFiles as file=>info)
+        {
+            // Font file embedding
+            _newobj();
+            m_FontFiles[file].n = m_n;
+            font = file_get_contents(m_fontpath + file,true);
+            if(!font) Error("Font file not found: ".file);
+            compressed = (substr(file,-2)==".z");
+            if(!compressed && isset(info.length2))
+                font = substr(font,6,info.length1).substr(font,6+info.length1+6,info.length2);
+            _outfmt(true, "<<\n/Length %d", strlen(font));
+            if(compressed) _outfmt(true, "/Filter /FlateDecode");
+            _outfmt(true, "/Length1 %d", info.length1);
+            if(isset(info["length2"]))
+                _outfmt(true, "/Length2 %d /Length3 0", info.length2);
+            _outfmt(true, ">>");
+            _putstream(font);
+            _outfmt(true, "endobj");
+        }
+#endif
+        font_map_t::iterator iter = m_fonts.begin();
+        font_map_t::iterator iend = m_fonts.end();
+        for(; iter != iend; ++iter)
+        {
+            // Font objects
+            st_pdf_font_base &font = *iter->second;
+            font.n = m_n+1;
+            e_font_type type = font.font.type;
+            std::string name = font.name;
+            if(type==e_font_type_core)
+            {
+                // Core font
+                _newobj();
+                _out("<<\n/Type /Font");
+                _out("/BaseFont /" + name);
+                _out("/Subtype /Type1");
+                if(name!="Symbol" && name!="ZapfDingbats")
+                    _out("/Encoding /WinAnsiEncoding");
+                _out(">>");
+                _out("endobj");
+            }
+#if 0
+            else if(type==e_font_type_type1 || type==e_font_type_ttf)
+            {
+                // Additional Type1 or TrueType/OpenType font
+                _newobj();
+                _out("<<\n/Type /Font");
+                _out("/BaseFont /" + name);
+                _out("/Subtype /" + type);
+                _out("/FirstChar 32 /LastChar 255");
+                _outfmt(true, "/Widths %d 0 R", (m_n+1));
+                _outfmt(true, "/FontDescriptor %d 0 R", (m_n+2));
+                if(isset(font["diffn"]))
+                    _outfmt(true, "/Encoding %d 0 R", nf+font.diffn);
+                else
+                    _out("/Encoding /WinAnsiEncoding");
+                _out(">>");
+                _out("endobj");
+                // Widths
+                _newobj();
+                cw = font.cw;
+                std::string s = "[";
+                s.reserve(1024);
+                for(i=32; i<=255; i++)
+                    pdf_sprintf_append(s, "%d ", cw[chr(i)]);
+                _out(s + "]");
+                _out("endobj");
+                // Descriptor
+                _newobj();
+                s = "<<\n/Type /FontDescriptor /FontName /" + name;
+                foreach(font["desc"] as k=>v)
+                s += " /".k." ".v;
+                if(!empty(font["file"]))
+                    s += " /FontFile".(type=="Type1" ? "" : "2")." ".m_FontFiles[font["file"]]["n"]." 0 R";
+                _outfmt(true, s.">>");
+                _outfmt(true, "endobj");
+            }
+            else
+            {
+                // Allow for additional types
+                mtd = "_put".strtolower(type);
+                if(!method_exists(this,mtd))
+                    Error("Unsupported font type: ".type);
+                mtd(font);
+            }
+#endif
+        }
+    }
+#line 2983 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putimages ()
+#line 2984 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        for(image_map_t::iterator iter = m_images.begin(); iter != m_images.end(); ++iter)
+        {
+            st_image &image = iter->second;
+            _putimage(image);
+            image.data.clear();
+            image.smask.clear();
+        }
+    }
+#line 2994 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putimage (st_image & info)
+#line 2995 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        _newobj();
+        info.n = m_n;
+        _out("<<\n/Type /XObject");
+        _out("/Subtype /Image");
+        _outfmt(true, "/Width %d", (int)info.w);
+        _outfmt(true, "/Height %d", (int)info.h);
+        if(info.cs=="Indexed")
+            _outfmt(true, "/ColorSpace [/Indexed /DeviceRGB %d %d 0 R]", (info.pal.size())/3-1, (m_n+1));
+        else
+        {
+            _out("/ColorSpace /" + info.cs);
+            if(info.cs=="DeviceCMYK")
+                _out("/Decode [1 0 1 0 1 0 1 0]");
+        }
+        _outfmt(true, "/BitsPerComponent %d", info.bpc);
+        if(!info.f.empty())
+            _out("/Filter /" + info.f);
+        if(!info.dp.empty())
+            _out("/DecodeParms\n<<\n" + info.dp + "\n>>");
+        if(!info.trns.empty())
+        {
+            std::string trns = "/Mask [";
+            for(int i=0, size = info.trns.size(); i<size; i++)
+            {
+                pdf_sprintf_append(trns, "%d", info.trns[i]);
+                trns += " ";
+                pdf_sprintf_append(trns, "%d", info.trns[i]);
+                trns += " ";
+            }
+            _out(trns + "]");
+        }
+        if(!info.smask.empty())
+            _outfmt(true, "/SMask %d  0 R", (m_n+1));
+        _outfmt(true, "/Length %d\n>>", info.data.size());
+        _putstream(info.data);
+        _out("endobj");
+        // Soft mask
+        if(!info.smask.empty())
+        {
+            std::string dp;
+            pdf_sprintf(dp, "/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns %d", (int)info.w);
+            st_image smask = info;
+            smask.cs = "DeviceGray";
+            smask.bpc = 8;
+            smask.dp = dp;
+            smask.data = info.smask;
+            _putimage(smask);
+        }
+        // Palette
+        if(info.cs=="Indexed")
+        {
+            std::string filter = (m_compress) ? "/Filter /FlateDecode " : "";
+            std::string zbuf, &pal =
+#ifdef PDF_USING_ZLIB
+                (m_compress) ? gzcompress(zbuf, info.pal) :
+#endif
+                info.pal;
+            _newobj();
+            _outfmt(true, "<<\n%s/Length %d\n>>", filter.c_str(), pal.size());
+            _putstream(pal);
+            _out("endobj");
+        }
+    }
+#line 3060 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putxobjectdict ()
+#line 3061 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        for(image_map_t::iterator iter = m_images.begin(); iter != m_images.end(); ++iter)
+            _outfmt(true, "/I%d %d 0 R", iter->second.i, iter->second.n);
+    }
+#line 3066 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putextgstates ()
+#line 3067 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        for (size_t i = 1, size = m_extgstates.size(); i <= size; ++i)
+        {
+            _newobj();
+            st_alpha_t &gs = m_extgstates[i-1];
+            gs.n = m_n;
+            _out("<<\n/Type /ExtGState");
+                _outfmt(true, "/ca %0.3f", gs.alpha);
+                _outfmt(true, "/CA %0.3f", gs.alpha);
+                _outfmt(true, "/BM /%s", gs.bm.c_str());
+            _out(">>\nendobj");
+        }
+    }
+#line 3081 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putjavascript ()
+#line 3082 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        _newobj();
+        m_n_js=m_n;
+        _outfmt(true, "<<\n/Names [(EmbeddedJS) %d 0 R]\n>>\nendobj", m_n+1);
+        _newobj();
+        _out("<<\n/S /JavaScript\n/JS (", false);
+        _out(_escape(m_javascript), false);
+        _out(")\n>>\nendobj");
+    }
+#line 3092 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putresourcedict ()
+#line 3093 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        _out("/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]");
+        _out("/Font\n<<");
+        for(font_map_t::iterator iter = m_fonts.begin(); iter != m_fonts.end(); ++iter)
+            _outfmt(true, "/F%d %d 0 R", iter->second->i, iter->second->n);
+        _outfmt(true, ">>");
+        _outfmt(true, "/XObject\n<<");
+        _putxobjectdict();
+        _outfmt(true, ">>");
+        if(m_extgstates.size())
+        {
+            _out("/ExtGState\n<<");
+            for(size_t i = 1, size = m_extgstates.size(); i <= size; ++i)
+            {
+                _outfmt(true, "/GS%d %d 0 R", i, m_extgstates[i-1].n);
+            }
+            _out(">>");
+        }
+    }
+#line 3113 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putresources ()
+#line 3114 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        _putextgstates();
+        _putfonts();
+        _putimages();
+        // Resource dictionary
+        m_offsets[2] = m_buffer.size();
+        _outfmt(true, "2 0 obj");
+        _outfmt(true, "<<");
+        _putresourcedict();
+        _out(">>\nendobj");
+        if (!m_javascript.empty())
+        {
+            _putjavascript();
+        }
+    }
+#line 3130 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putinfo ()
+#line 3131 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        std::string str = _escape(FPDF_VERSION);
+        _outfmt(true, "/Producer (CppPDF %s)", str.c_str());
+        if(!m_title.empty())
+        {
+            str = _escape(m_title);
+            _out("/Title (" + str + ")");
+        }
+        if(!m_subject.empty())
+        {
+            str = _escape(m_subject);
+            _out("/Subject (" + str + ")");
+        }
+        if(!m_author.empty())
+        {
+            str = _escape(m_author);
+            _out("/Author (" + str + ")");
+        }
+        if(!m_keywords.empty())
+        {
+            str = _escape(m_keywords);
+            _out("/Keywords (" + str + ")");
+        }
+        if(!m_creator.empty())
+        {
+            str = _escape(m_creator);
+            _out("/Creator (" + str + ")");
+        }
+        time_t rawtime;
+        struct tm * timeinfo;
+        time ( &rawtime );
+        timeinfo = localtime ( &rawtime );
+        strftime (m_scratch_buf,sizeof(m_scratch_buf),"/CreationDate (D:%Y%m%d%H%M%S)", timeinfo);
+        _out(m_scratch_buf);
+    }
+#line 3167 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putcatalog ()
+#line 3168 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        _outfmt(true, "/Type /Catalog");
+        _outfmt(true, "/Pages 1 0 R");
+        if(m_CustomZoom)
+            _outfmt(true, "/OpenAction [3 0 R /XYZ null null %.2f]", m_CustomZoom/100.0);
+        else if(m_ZoomMode==e_zoom_fullpage)
+            _outfmt(true, "/OpenAction [3 0 R /Fit]");
+        else if(m_ZoomMode==e_zoom_fullwidth)
+            _outfmt(true, "/OpenAction [3 0 R /FitH null]");
+        else if(m_ZoomMode==e_zoom_real)
+            _outfmt(true, "/OpenAction [3 0 R /XYZ null null 1]");
+        if(m_LayoutMode==e_layout_single)
+            _outfmt(true, "/PageLayout /SinglePage");
+        else if(m_LayoutMode==e_layout_continuous)
+            _outfmt(true, "/PageLayout /OneColumn");
+        else if(m_LayoutMode==e_layout_two)
+            _outfmt(true, "/PageLayout /TwoColumnLeft");
+        if (!m_javascript.empty())
+        {
+            _outfmt(true, "/Names\n<<\n/JavaScript %d 0 R\n>>", m_n_js);
+        }
+    }
+#line 3191 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_putheader ()
+#line 3192 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        _out("%PDF-" + m_PDFVersion);
+    }
+#line 3196 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_puttrailer ()
+#line 3197 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        _outfmt(true, "/Size %d", (m_n+1));
+        _outfmt(true, "/Root %d 0 R", m_n);
+        _outfmt(true, "/Info %d 0 R", (m_n-1));
+    }
+#line 3203 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+void FPDF::_enddoc ()
+#line 3204 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/fpdf.zz"
+    {
+        if(m_extgstates.size() && (m_PDFVersion < "1.4")) m_PDFVersion = "1.4";
+        _putheader();
+        _putpages();
+        _putresources();
+        // Info
+        _newobj();
+        _out("<<");
+        _putinfo();
+        _out(">>\nendobj");
+        // Catalog
+        _newobj();
+        _out("<<");
+        _putcatalog();
+        _out(">>\nendobj");
+        //save begining of xref
+        int saved_startxref = m_buffer.size();
+        // Cross-ref
+        _out("xref");
+        _outfmt(true, "0 %d", (m_n+1));
+        _out("0000000000 65535 f ");
+        for(int i=1; i<=m_n; i++)
+        {
+            _outfmt(true, "%010d 00000 n ",m_offsets[i]);
+        }
+        // Trailer
+        _out("trailer\n<<");
+        _puttrailer();
+        _out(">>\nstartxref");
+        _outfmt(true, "%d", saved_startxref);
+        _out("%%EOF", false);
+        m_state = 3;
+    }
+#undef LZZ_INLINE

+ 321 - 0
ext/pdf-font.cpp

@@ -0,0 +1,321 @@
+// pdf-font.cpp
+//
+
+#include "pdf-font.h"
+#line 7 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+#include <cstring>
+#define LZZ_INLINE inline
+#line 25 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+st_pdf_font_base::st_pdf_font_base (st_pdf_font_core & f)
+#line 25 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : font (f)
+#line 25 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                 {
+        i = n = 0;
+        name = "None";
+    }
+#line 32 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_Courier::pdf_font_Courier ()
+#line 32 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_Courier)
+#line 32 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                              {
+        name = "Courier";
+    }
+#line 38 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_CourierOblique::pdf_font_CourierOblique ()
+#line 38 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_Courier)
+#line 38 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                                     {
+        name = "Courier-Oblique";
+    }
+#line 44 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_CourierBold::pdf_font_CourierBold ()
+#line 44 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_Courier)
+#line 44 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                                  {
+        name = "Courier-Bold";
+    }
+#line 50 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_CourierBoldOblique::pdf_font_CourierBoldOblique ()
+#line 50 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_Courier)
+#line 50 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                                         {
+        name = "Courier-BoldOblique";
+    }
+#line 56 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_Helvetica::pdf_font_Helvetica ()
+#line 56 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_Helvetica)
+#line 56 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                                  {
+        name = "Helvetica";
+    }
+#line 62 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_HelveticaOblique::pdf_font_HelveticaOblique ()
+#line 62 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_Helvetica)
+#line 62 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                                         {
+        name = "Helvetica-Oblique";
+    }
+#line 68 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_HelveticaBold::pdf_font_HelveticaBold ()
+#line 68 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_HelveticaBold)
+#line 68 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                                          {
+        name = "Helvetica-Bold";
+    }
+#line 74 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_HelveticaBoldOblique::pdf_font_HelveticaBoldOblique ()
+#line 74 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_HelveticaBold)
+#line 74 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                                                 {
+        name = "Helvetica-BoldOblique";
+    }
+#line 80 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_Times::pdf_font_Times ()
+#line 80 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_Times)
+#line 80 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                          {
+        name = "Times-Roman";
+    }
+#line 86 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_TimesOblique::pdf_font_TimesOblique ()
+#line 86 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_TimesOblique)
+#line 86 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                                        {
+        name = "Times-Oblique";
+    }
+#line 92 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_TimesBold::pdf_font_TimesBold ()
+#line 92 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_TimesBold)
+#line 92 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                                  {
+        name = "Times-Bold";
+    }
+#line 98 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_TimesBoldOblique::pdf_font_TimesBoldOblique ()
+#line 98 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_TimesBoldOblique)
+#line 98 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                                                {
+        name = "Times-BoldItalic";
+    }
+#line 104 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_Symbol::pdf_font_Symbol ()
+#line 104 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_Symbol)
+#line 104 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                            {
+        name = "Symbol";
+    }
+#line 110 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+pdf_font_ZapfDingbats::pdf_font_ZapfDingbats ()
+#line 110 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+  : st_pdf_font_base (pdf_font_core_ZapfDingbats)
+#line 110 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                                                        {
+        name = "ZapfDingbats";
+    }
+#line 115 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+bool isPdfFontCore (char const * fname)
+#line 115 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+                                     {
+    static const char *core[] = {
+        "courier", "helvetica", "times", "symbol", "zapfdingbats",
+        0
+    };
+    const char *p = core[0];
+    for(int i=0; p; p = core[++i]){
+        if(strcmp(p, fname) == 0) return true;
+    }
+    return false;
+}
+#line 127 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+st_pdf_font_core pdf_font_core_Courier = {
+    /*type*/e_font_type_core,
+    /*up*/ -100, /*ut*/ 50,
+    /*cw*/ {
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
+	600,
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
+	600,600,600,600,600,600,600,600,600,600,600,600,600,600
+	}
+};
+#line 148 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+st_pdf_font_core pdf_font_core_Helvetica = {
+    /*type*/e_font_type_core,
+    /*up*/ -100, /*ut*/ 50,
+    /*cw*/ {
+	278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,
+	278,278,278,278,278,278,278,278,278,278,278,278,355,556,556,889,667,191,333,333,389,584,
+	278,333,278,278,556,556,556,556,556,556,556,556,556,556,278,278,584,584,584,556,1015,667,
+	667,722,722,667,611,778,722,278,500,667,556,833,722,778,667,778,722,667,611,722,667,944,
+	667,667,611,278,278,278,469,556,333,556,556,500,556,556,278,556,556,222,222,500,222,833,
+	556,556,556,556,333,500,278,556,500,722,500,500,500,334,260,334,584,350,556,350,222,556,
+	333,1000,556,556,333,1000,667,333,1000,350,611,350,350,222,222,333,333,350,556,1000,333,
+	1000,
+	500,333,944,350,500,667,278,333,556,556,556,556,260,556,333,737,370,556,584,333,737,333,
+	400,584,333,333,333,556,537,278,333,333,365,556,834,834,834,611,667,667,667,667,667,667,
+	1000,722,667,667,667,667,278,278,278,278,722,722,778,778,778,778,778,584,778,722,722,722,
+	722,667,667,611,556,556,556,556,556,556,889,500,556,556,556,556,278,278,278,278,556,556,
+	556,556,556,556,556,584,611,556,556,556,556,500,556,500
+	}
+};
+#line 169 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+st_pdf_font_core pdf_font_core_HelveticaBold = {
+    /*type*/e_font_type_core,
+    /*up*/ -100, /*ut*/ 50,
+    /*cw*/ {
+	278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,
+	278,278,278,278,278,278,278,278,278,278,278,333,474,556,556,889,722,238,333,333,389,584,
+	278,333,278,278,556,556,556,556,556,556,556,556,556,556,333,333,584,584,584,611,975,722,
+	722,722,722,667,611,778,722,278,556,722,611,833,722,778,667,778,722,667,611,722,667,944,
+	667,667,611,333,278,333,584,556,333,556,611,556,611,556,333,611,611,278,278,556,278,889,
+	611,611,611,611,389,556,333,611,556,778,556,556,500,389,280,389,584,350,556,350,278,556,
+	500,1000,556,556,333,1000,667,333,1000,350,611,350,350,278,278,500,500,350,556,1000,333,
+	1000,
+	556,333,944,350,500,667,278,333,556,556,556,556,280,556,333,737,370,556,584,333,737,333,
+	400,584,333,333,333,611,556,278,333,333,365,556,834,834,834,611,722,722,722,722,722,722,
+	1000,722,667,667,667,667,278,278,278,278,722,722,778,778,778,778,778,584,778,722,722,722,
+	722,667,667,611,556,556,556,556,556,556,889,556,556,556,556,556,278,278,278,278,611,611,
+	611,611,611,611,611,584,611,611,611,611,611,556,611,556
+	}
+};
+#line 190 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+st_pdf_font_core pdf_font_core_Times = {
+    /*type*/e_font_type_core,
+    /*up*/ -100, /*ut*/ 50,
+    /*cw*/ {
+	250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,
+	250,250,250,250,250,250,250,250,250,250,250,333,408,500,500,833,778,180,333,333,500,564,
+	250,333,250,278,500,500,500,500,500,500,500,500,500,500,278,278,564,564,564,444,921,722,
+	667,667,722,611,556,722,722,333,389,722,611,889,722,722,556,722,667,556,611,722,722,944,
+	722,722,611,333,278,333,469,500,333,444,500,444,500,444,333,500,500,278,278,500,278,778,
+	500,500,500,500,333,389,278,500,500,722,500,500,444,480,200,480,541,350,500,350,333,500,
+	444,1000,500,500,333,1000,556,333,889,350,611,350,350,333,333,444,444,350,500,1000,333,
+	980,
+	389,333,722,350,444,722,250,333,500,500,500,500,200,500,333,760,276,500,564,333,760,333,
+	400,564,300,300,333,500,453,250,333,300,310,500,750,750,750,444,722,722,722,722,722,722,
+	889,667,611,611,611,611,333,333,333,333,722,722,722,722,722,722,722,564,722,722,722,722,
+	722,722,556,500,444,444,444,444,444,444,667,444,444,444,444,444,278,278,278,278,500,500,
+	500,500,500,500,500,564,500,500,500,500,500,500,500,500
+	}
+};
+#line 210 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+st_pdf_font_core pdf_font_core_TimesOblique = {
+    /*type*/e_font_type_core,
+    /*up*/ -100, /*ut*/ 50,
+    /*cw*/ {
+	250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,
+	250,250,250,250,250,250,250,250,250,250,250,333,420,500,500,833,778,214,333,333,500,675,
+	250,333,250,278,500,500,500,500,500,500,500,500,500,500,333,333,675,675,675,500,920,611,
+	611,667,722,611,611,722,722,333,444,667,556,833,667,722,611,722,611,500,556,722,611,833,
+	611,556,556,389,278,389,422,500,333,500,500,444,500,444,278,500,500,278,278,444,278,722,
+	500,500,500,500,389,389,278,500,444,667,444,444,389,400,275,400,541,350,500,350,333,500,
+	556,889,500,500,333,1000,500,333,944,350,556,350,350,333,333,556,556,350,500,889,333,
+	980,
+	389,333,667,350,389,556,250,389,500,500,500,500,275,500,333,760,276,500,675,333,760,333,
+	400,675,300,300,333,500,523,250,333,300,310,500,750,750,750,500,611,611,611,611,611,611,
+	889,667,611,611,611,611,333,333,333,333,722,667,722,722,722,722,722,675,722,722,722,722,
+	722,556,611,500,500,500,500,500,500,500,667,444,444,444,444,444,278,278,278,278,500,500,
+	500,500,500,500,500,675,500,500,500,500,500,444,500,444
+	}
+};
+#line 230 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+st_pdf_font_core pdf_font_core_TimesBold = {
+    /*type*/e_font_type_core,
+    /*up*/ -100, /*ut*/ 50,
+    /*cw*/ {
+	250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,
+	250,250,250,250,250,250,250,250,250,250,250,333,555,500,500,1000,833,278,333,333,500,570,
+	250,333,250,278,500,500,500,500,500,500,500,500,500,500,333,333,570,570,570,500,930,722,
+	667,722,722,667,611,778,778,389,500,778,667,944,722,778,611,778,722,556,667,722,722,1000,
+	722,722,667,333,278,333,581,500,333,500,556,444,556,444,333,500,556,278,333,556,278,833,
+	556,500,556,556,444,389,333,556,500,722,500,500,444,394,220,394,520,350,500,350,333,500,
+	500,1000,500,500,333,1000,556,333,1000,350,667,350,350,333,333,500,500,350,500,1000,333,
+	1000,
+	389,333,722,350,444,722,250,333,500,500,500,500,220,500,333,747,300,500,570,333,747,333,
+	400,570,300,300,333,556,540,250,333,300,330,500,750,750,750,500,722,722,722,722,722,722,
+	1000,722,667,667,667,667,389,389,389,389,722,722,778,778,778,778,778,570,778,722,722,722,
+	722,722,611,556,500,500,500,500,500,500,722,444,444,444,444,444,278,278,278,278,500,556,
+	500,500,500,500,500,570,500,556,556,556,556,500,556,500
+	}
+};
+#line 250 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+st_pdf_font_core pdf_font_core_TimesBoldOblique = {
+    /*type*/e_font_type_core,
+    /*up*/ -100, /*ut*/ 50,
+    /*cw*/ {
+	250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,
+	250,250,250,250,250,250,250,250,250,250,250,389,555,500,500,833,778,278,333,333,500,570,
+	250,333,250,278,500,500,500,500,500,500,500,500,500,500,333,333,570,570,570,500,832,667,
+	667,667,722,667,667,722,778,389,500,667,611,889,722,722,611,722,667,556,611,722,667,889,
+	667,611,611,333,278,333,570,500,333,500,500,444,500,444,333,500,556,278,278,500,278,778,
+	556,500,500,500,389,389,278,556,444,667,500,444,389,348,220,348,570,350,500,350,333,500,
+	500,1000,500,500,333,1000,556,333,944,350,611,350,350,333,333,500,500,350,500,1000,333,
+	1000,
+	389,333,722,350,389,611,250,389,500,500,500,500,220,500,333,747,266,500,606,333,747,333,
+	400,570,300,300,333,576,500,250,333,300,300,500,750,750,750,500,667,667,667,667,667,667,
+	944,667,667,667,667,667,389,389,389,389,722,722,722,722,722,722,722,570,722,722,722,722,
+	722,611,611,500,500,500,500,500,500,500,722,444,444,444,444,444,278,278,278,278,500,556,
+	500,500,500,500,500,570,500,556,556,556,556,444,500,444
+	}
+};
+#line 270 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+st_pdf_font_core pdf_font_core_Symbol = {
+    /*type*/e_font_type_core,
+    /*up*/ -100, /*ut*/ 50,
+    /*cw*/ {
+	250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,
+	250,250,250,250,250,250,250,250,250,250,250,333,713,500,549,833,778,439,333,333,500,549,
+	250,549,250,278,500,500,500,500,500,500,500,500,500,500,278,278,549,549,549,444,549,722,
+	667,722,612,611,763,603,722,333,631,722,686,889,722,722,768,741,556,592,611,690,439,768,
+	645,795,611,333,863,333,658,500,500,631,549,549,494,439,521,411,603,329,603,549,549,576,
+	521,549,549,521,549,603,439,576,713,686,493,686,494,480,200,480,549,0,0,0,0,0,
+	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+	0,0,0,0,0,0,750,620,247,549,167,713,500,753,753,753,753,1042,987,603,987,603,
+	400,549,411,549,549,713,494,460,549,549,549,549,1000,603,1000,658,823,686,795,987,768,768,
+	823,768,768,713,713,713,713,713,713,713,768,713,790,790,890,823,549,250,713,603,603,1042,
+	987,603,987,603,494,329,790,790,786,713,384,384,384,384,384,384,494,494,494,494,0,329,
+	274,686,686,686,384,384,384,384,384,384,494,494,494,0
+	}
+};
+#line 289 "/home/mingo/dev/dadbiz++/ourbiz-uk/parts/pdf-font.zz"
+st_pdf_font_core pdf_font_core_ZapfDingbats = {
+    /*type*/e_font_type_core,
+    /*up*/ -100, /*ut*/ 50,
+    /*cw*/ {
+	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+	0,0,0,0,0,0,0,0,0,0,278,974,961,974,980,719,789,790,791,690,960,939,
+	549,855,911,933,911,945,974,755,846,762,761,571,677,763,760,759,754,494,552,537,577,692,
+	786,788,788,790,793,794,816,823,789,841,823,833,816,831,923,744,723,749,790,792,695,776,
+	768,792,759,707,708,682,701,826,815,789,789,707,687,696,689,786,787,713,791,785,791,873,
+	761,762,762,759,759,892,892,788,784,438,138,277,415,392,392,668,668,0,390,390,317,317,
+	276,276,509,509,410,410,234,234,334,334,0,0,0,0,0,0,0,0,0,0,0,0,
+	0,0,0,0,0,0,0,732,544,544,910,667,760,760,776,595,694,626,788,788,788,788,
+	788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,
+	788,788,788,788,788,788,788,788,788,788,788,788,788,788,894,838,1016,458,748,924,748,918,
+	927,928,928,834,873,828,924,924,917,930,931,463,883,836,836,867,867,696,696,874,0,874,
+	760,946,771,865,771,888,967,888,831,873,927,970,918,0
+	}
+};
+#undef LZZ_INLINE

+ 98 - 0
ext/pdf-font.h

@@ -0,0 +1,98 @@
+// pdf-font.h
+//
+
+#ifndef LZZ_pdf_font_h
+#define LZZ_pdf_font_h
+#include <string>
+#include <set>
+#define LZZ_INLINE inline
+enum e_font_type
+{
+  e_font_type_core,
+  e_font_type_type1,
+  e_font_type_ttf
+};
+typedef int font_width_t;
+struct st_pdf_font_core
+{
+  e_font_type type;
+  int up;
+  int ut;
+  font_width_t (cw) [256];
+};
+struct st_pdf_font_base
+{
+  int i;
+  int n;
+  char const * name;
+  st_pdf_font_core & font;
+  st_pdf_font_base (st_pdf_font_core & f);
+};
+struct pdf_font_Courier : public st_pdf_font_base
+{
+  pdf_font_Courier ();
+};
+struct pdf_font_CourierOblique : public st_pdf_font_base
+{
+  pdf_font_CourierOblique ();
+};
+struct pdf_font_CourierBold : public st_pdf_font_base
+{
+  pdf_font_CourierBold ();
+};
+struct pdf_font_CourierBoldOblique : public st_pdf_font_base
+{
+  pdf_font_CourierBoldOblique ();
+};
+struct pdf_font_Helvetica : public st_pdf_font_base
+{
+  pdf_font_Helvetica ();
+};
+struct pdf_font_HelveticaOblique : public st_pdf_font_base
+{
+  pdf_font_HelveticaOblique ();
+};
+struct pdf_font_HelveticaBold : public st_pdf_font_base
+{
+  pdf_font_HelveticaBold ();
+};
+struct pdf_font_HelveticaBoldOblique : public st_pdf_font_base
+{
+  pdf_font_HelveticaBoldOblique ();
+};
+struct pdf_font_Times : public st_pdf_font_base
+{
+  pdf_font_Times ();
+};
+struct pdf_font_TimesOblique : public st_pdf_font_base
+{
+  pdf_font_TimesOblique ();
+};
+struct pdf_font_TimesBold : public st_pdf_font_base
+{
+  pdf_font_TimesBold ();
+};
+struct pdf_font_TimesBoldOblique : public st_pdf_font_base
+{
+  pdf_font_TimesBoldOblique ();
+};
+struct pdf_font_Symbol : public st_pdf_font_base
+{
+  pdf_font_Symbol ();
+};
+struct pdf_font_ZapfDingbats : public st_pdf_font_base
+{
+  pdf_font_ZapfDingbats ();
+};
+bool isPdfFontCore (char const * fname);
+extern st_pdf_font_core pdf_font_core_Courier;
+extern st_pdf_font_core pdf_font_core_Helvetica;
+extern st_pdf_font_core pdf_font_core_HelveticaBold;
+extern st_pdf_font_core pdf_font_core_Times;
+extern st_pdf_font_core pdf_font_core_TimesOblique;
+extern st_pdf_font_core pdf_font_core_TimesBold;
+extern st_pdf_font_core pdf_font_core_TimesBoldOblique;
+extern st_pdf_font_core pdf_font_core_Symbol;
+extern st_pdf_font_core pdf_font_core_ZapfDingbats;
+#undef LZZ_INLINE
+#endif

+ 780 - 0
ext/sqfltk.cpp

@@ -0,0 +1,780 @@
+#ifdef WITH_FLTK
+
+#define LUAFLTK
+
+#include <FL/Fl.H>
+#include <FL/Fl_Widget.H>
+#include <FL/Fl_Box.H>
+#include <FL/Fl_Button.H>
+#include <FL/Fl_Group.H>
+#include <FL/Fl_Window.H>
+#include <FL/Fl_Double_Window.H>
+#include <FL/Fl_Button.H>
+#include <FL/Fl_Light_Button.H>
+#include <FL/Fl_Check_Button.H>
+#include <FL/Fl_Radio_Button.H>
+#include <FL/Fl_Menu_Item.H>
+#include <FL/Fl_Menu_.H>
+#include <FL/Fl_Choice.H>
+#include <FL/Fl_Input_.H>
+#include <FL/Fl_Input.H>
+#include <FL/Fl_Float_Input.H>
+#include <FL/Fl_Int_Input.H>
+#include <FL/Fl_Output.H>
+#include <FL/Fl_Secret_Input.H>
+#include <FL/Fl_Text_Display.H>
+#include <FL/Fl_Text_Editor.H>
+#include <FL/Fl_Pack.H>
+#include <FL/Fl_Tabs.H>
+#include <FL/Flv_List.H>
+#include <FL/Flv_Table.H>
+#include <FL/Fl_Image.H>
+#include <FL/Fl_PNG_Image.H>
+#include <FL/Fl_JPEG_Image.H>
+
+#include <squirrel.h>
+
+#include "sqfltk.h"
+
+struct MyFltkUData {
+    HSQOBJECT self;
+    HSQOBJECT udata;
+    HSQUIRRELVM v;
+};
+
+#define FLTK_TAG(tag) SQFLTK_##tag##_TYPE_TAG
+
+#define CREATE_TAG(tag) \
+static const char* FLTK_TAG(tag) = #tag
+
+
+CREATE_TAG(Fl);
+CREATE_TAG(Fl_Widget);
+CREATE_TAG(Fl_Box);
+CREATE_TAG(Fl_Button);
+CREATE_TAG(Fl_Light_Button);
+CREATE_TAG(Fl_Check_Button);
+CREATE_TAG(Fl_Radio_Button);
+CREATE_TAG(Fl_Menu_);
+CREATE_TAG(Fl_Menu_Item);
+CREATE_TAG(Fl_Choice);
+CREATE_TAG(Fl_Input_);
+CREATE_TAG(Fl_Input);
+CREATE_TAG(Fl_Float_Input);
+CREATE_TAG(Fl_Int_Input);
+CREATE_TAG(Fl_Output);
+CREATE_TAG(Fl_Secret_Input);
+CREATE_TAG(Fl_Group);
+CREATE_TAG(Fl_Pack);
+CREATE_TAG(Fl_Tabs);
+CREATE_TAG(Flv_List);
+CREATE_TAG(Flv_Table);
+CREATE_TAG(Fl_Text_Display);
+CREATE_TAG(Fl_Text_Editor);
+CREATE_TAG(Fl_Text_Editor_Buffered);
+CREATE_TAG(Fl_Window);
+CREATE_TAG(Fl_Double_Window);
+
+CREATE_TAG(Fl_Image);
+CREATE_TAG(Fl_PNG_Image);
+CREATE_TAG(Fl_JPEG_Image);
+
+static void do_register_object_and_instance(HSQUIRRELVM sqvm, int instance_idx, void *cptr){
+    sq_pushregistrytable(sqvm);
+    sq_pushuserpointer(sqvm, cptr);
+    HSQOBJECT obj; sq_resetobject(&obj);
+    sq_getstackobj(sqvm, instance_idx, &obj);
+    sq_pushobject(sqvm, obj);
+    sq_rawset(sqvm, -3);
+    sq_pop(sqvm, -1);
+}
+
+#define SETUP_FL_KLASS(v, Klass) \
+	Klass *self = NULL; \
+	{ if(SQ_FAILED(sq_getinstanceup(v,1,(SQUserPointer*)&self,(void*)FLTK_TAG(Klass)))) \
+		return SQ_ERROR; }
+
+#define SETUP_FL_WIDGET(v) SETUP_FL_KLASS(v, Fl_Widget)
+
+#define NOTHING(a)
+#define AS_IS(a) a
+
+#define FLTK_CONSTRUCTOR_RELEASE(Klass, RELEASE_HOOK, _release_hook)\
+static SQInteger _##Klass##_constructor(HSQUIRRELVM sqvm)\
+{\
+	const SQChar *label;\
+	SQInteger argc, x,y,w,h;\
+	Klass *cptr;\
+	argc = sq_gettop(sqvm);\
+	if(argc > 5){\
+	    sq_getinteger(sqvm, 2, &x);\
+	    sq_getinteger(sqvm, 3, &y);\
+	    sq_getinteger(sqvm, 4, &w);\
+	    sq_getinteger(sqvm, 5, &h);\
+        if(argc == 6) sq_getstring(sqvm, 6, &label);\
+        else label = NULL;\
+	    cptr = new Klass(x,y,w,h,label);\
+	    do_register_object_and_instance(sqvm, 1, cptr);\
+	} else\
+        return sq_throwerror(sqvm, _SC("Wrong number of parameters."));\
+\
+    sq_setinstanceup(sqvm, 1, cptr);\
+    RELEASE_HOOK(sq_setreleasehook(sqvm,1,_release_hook));\
+	return 1;\
+}
+
+#define FLTK_CONSTRUCTOR(Klass) FLTK_CONSTRUCTOR_RELEASE(Klass, NOTHING, a)
+
+#define FL_WIDGET_GETSET_STR(funcNAME) \
+static SQInteger _flwidget_##funcNAME(HSQUIRRELVM sqvm) \
+{\
+    SETUP_FL_WIDGET(sqvm);\
+    SQInteger argc = sq_gettop(sqvm);\
+    const SQChar *funcNAME = NULL;\
+    if(argc > 0){\
+        sq_getstring(sqvm, 2, &funcNAME);\
+        self->funcNAME(funcNAME);\
+        return 0;\
+    }\
+    funcNAME = self->funcNAME();\
+    if(funcNAME) sq_pushstring(sqvm, funcNAME, -1);\
+    else sq_pushnull(sqvm);\
+	return 1;\
+}
+
+#define FL_WIDGET_GETSET_INT0(funcNAME, typeNAME) \
+static SQInteger _flwidget_##funcNAME(HSQUIRRELVM sqvm) \
+{\
+    SETUP_FL_WIDGET(sqvm);\
+    SQInteger argc = sq_gettop(sqvm);\
+    SQInteger funcNAME;\
+    if(argc > 0){\
+        sq_getinteger(sqvm, 2, &funcNAME);\
+        self->funcNAME((typeNAME)funcNAME);\
+        return 0;\
+    }\
+    sq_pushinteger(sqvm, self->funcNAME());\
+	return 1;\
+}
+
+#define FL_WIDGET_GETSET_INT(funcNAME) FL_WIDGET_GETSET_INT0(funcNAME, int)
+
+#define FL_WIDGET_VOID_CALL(funcNAME) \
+static SQInteger _flwidget_##funcNAME(HSQUIRRELVM sqvm) \
+{\
+    SETUP_FL_WIDGET(sqvm);\
+    self->funcNAME();\
+	return 0;\
+}
+
+#define FL_WIDGET_VOID_CALL_2INT(funcNAME) \
+static SQInteger _flwidget_##funcNAME(HSQUIRRELVM sqvm) \
+{\
+    SETUP_FL_WIDGET(sqvm);\
+    SQInteger i1, i2;\
+    sq_getinteger(sqvm, 2, &i1);\
+    sq_getinteger(sqvm, 3, &i2);\
+    self->funcNAME(i1,i2);\
+	return 0;\
+}
+
+#define FL_WIDGET_VOID_CALL_4INT(funcNAME) \
+static SQInteger _flwidget_##funcNAME(HSQUIRRELVM sqvm) \
+{\
+    SETUP_FL_WIDGET(sqvm);\
+    SQInteger i1, i2, i3, i4;\
+    sq_getinteger(sqvm, 2, &i1);\
+    sq_getinteger(sqvm, 3, &i2);\
+    sq_getinteger(sqvm, 4, &i3);\
+    sq_getinteger(sqvm, 5, &i4);\
+    self->funcNAME(i1,i2,i3,i4);\
+	return 0;\
+}
+
+#define FL_WIDGET_INT_CALL(funcNAME) \
+static SQInteger _flwidget_##funcNAME(HSQUIRRELVM sqvm) \
+{\
+    SETUP_FL_WIDGET(sqvm);\
+    sq_pushinteger(sqvm, self->funcNAME());\
+	return 1;\
+}
+
+static void sq_call_fl_virtual(void *self, const SQChar *func_name){
+    HSQUIRRELVM sqvm = (HSQUIRRELVM) Fl::user_data;
+    //sq_reservestack(sqvm, 20);
+    SQInteger top = sq_gettop(sqvm);
+    sq_pushregistrytable(sqvm);
+    sq_pushuserpointer(sqvm, self);
+    if(sq_rawget(sqvm, -2) == SQ_OK){
+        sq_pushstring(sqvm, func_name, -1);
+        sq_get(sqvm, -2);
+        SQObjectType toptype = sq_gettype(sqvm, -1);
+        if(toptype == OT_CLOSURE || toptype == OT_NATIVECLOSURE){
+            sq_push(sqvm, -2); //this
+            sq_call(sqvm, 1, SQFalse, SQTrue);
+        }
+    }
+    sq_settop(sqvm, top);
+}
+
+
+typedef struct {
+    HSQOBJECT callback;
+    HSQOBJECT callee;
+    HSQOBJECT udata;
+} st_mycb;
+
+//static st_mycb static_cb;
+
+static void free_st_mycb(HSQUIRRELVM sqvm, st_mycb *cb){
+    sq_release(sqvm, &cb->callback);
+    sq_release(sqvm, &cb->udata);
+    sq_free((void*)cb, sizeof(st_mycb));
+}
+
+static void At_Widget_Destroy(Fl_Widget *widget){
+printf("%d %p At_Widget_Destroy\n", __LINE__, widget);
+    Fl_Callback_p cb = widget->callback();
+    if(!cb || cb == Fl_Widget::default_callback) {
+        //no need to check
+        return;
+    }
+    HSQUIRRELVM sqvm = (HSQUIRRELVM) Fl::user_data;
+    SQInteger savedTop = sq_gettop(sqvm);
+printf("%d %p %d At_Widget_Destroy\n", __LINE__, widget, sq_gettop(sqvm));
+    sq_pushregistrytable(sqvm);
+printf("%d %p %d At_Widget_Destroy\n", __LINE__, widget, sq_gettop(sqvm));
+    sq_pushuserpointer(sqvm, widget);
+printf("%d %p %d At_Widget_Destroy\n", __LINE__, widget, sq_gettop(sqvm));
+    int rc = sq_deleteslot(sqvm, -2, SQTrue);
+printf("%d %p %d At_Widget_Destroy\n", __LINE__, widget, sq_gettop(sqvm));
+printf("%d %p %d %s At_Widget_Destroy\n", __LINE__, widget, rc, sq_getlasterror_str(sqvm));
+    //if(sq_deleteslot(sqvm, -2, SQTrue) == SQ_OK){
+    if(rc == SQ_OK){
+printf("%d %p At_Widget_Destroy\n", __LINE__, widget);
+        if(sq_gettype(sqvm, -1) != OT_NULL){
+            //////////////////////////////nota all will have user pointer !!!!!!!!
+            SQUserPointer ptr;
+            sq_getuserpointer(sqvm, -1, &ptr);
+            free_st_mycb(sqvm, (st_mycb*)ptr);
+        }
+    }
+    sq_settop(sqvm, savedTop);
+}
+
+static void fltk_calback_hook(Fl_Widget *sender, void* udata){
+    printf("Sender %p, data %p\n", sender, udata);
+    HSQUIRRELVM sqvm = (HSQUIRRELVM) Fl::user_data;
+    SQInteger savedTop = sq_gettop(sqvm);
+    st_mycb *mycb = (st_mycb *)udata;
+    sq_pushobject(sqvm, mycb->callback);
+    sq_pushroottable(sqvm); //’this’ (function environment object)
+    sq_pushobject(sqvm, mycb->callee);
+    sq_pushobject(sqvm, mycb->udata);
+    printf("%d\n", sq_call(sqvm, 3, SQFalse, SQTrue));
+    sq_settop(sqvm, savedTop);
+}
+
+static SQInteger _flwidget_callback(HSQUIRRELVM sqvm)
+{
+//printf("%d %s\n", __LINE__, __FILE__);
+    SETUP_FL_WIDGET(sqvm);
+    SQInteger argc = sq_gettop(sqvm);
+    Fl_Callback_p cb = self->callback();
+    if(cb == Fl_Widget::default_callback){
+        cb = 0;
+    }
+    if(argc == 1){
+        if(cb) sq_pushuserpointer(sqvm, (void*)cb);
+        else sq_pushnull(sqvm);
+        return 1;
+    }
+    if(argc >= 2){
+        int ptypecb = sq_gettype(sqvm, 2);
+        if(cb || ptypecb == OT_NULL) { //not allways the cb was set by us
+            At_Widget_Destroy(self);
+            if(ptypecb == OT_NULL) {
+                self->callback((Fl_Callback*)NULL, (void*)NULL);
+                return 0;
+            }
+        }
+        st_mycb *mycb = (st_mycb *)sq_malloc(sizeof(st_mycb));
+        sq_resetobject(&mycb->callback); //initializes the object handle (sets to NULL)
+        sq_resetobject(&mycb->callee);
+        sq_resetobject(&mycb->udata);
+        sq_getstackobj(sqvm, 2, &mycb->callback);//fetches an handle of the function you passed
+        if(sq_gettop(sqvm) > 2) { //we have user data too
+            sq_getstackobj(sqvm, 3, &mycb->udata);
+            sq_addref(sqvm,&mycb->udata);
+        }
+        if(sq_type(mycb->callback) == OT_CLOSURE || sq_type(mycb->callback) == OT_NATIVECLOSURE){
+            sq_addref(sqvm,&mycb->callback);
+            sq_getcallee(sqvm);
+            sq_getstackobj(sqvm, -1, &mycb->callee);
+            self->callback(&fltk_calback_hook, mycb);
+            //registry for free when widget is destroyed
+            sq_pushregistrytable(sqvm);
+            sq_pushuserpointer(sqvm, self);
+            sq_pushuserpointer(sqvm, mycb);
+            sq_rawset(sqvm, -2);
+            printf("Button %p\n", self);
+        }
+    }
+	return 0;
+}
+
+FL_WIDGET_GETSET_INT(align);
+FL_WIDGET_GETSET_INT(argument);
+//FL_WIDGET_GETSET_INT(box);
+FL_WIDGET_GETSET_INT(color);
+FL_WIDGET_GETSET_INT(selection_color);
+FL_WIDGET_GETSET_STR(label);
+FL_WIDGET_GETSET_INT(labelcolor);
+FL_WIDGET_GETSET_INT(labelfont);
+FL_WIDGET_GETSET_INT(labelsize);
+//FL_WIDGET_GETSET_INT(labeltype);
+FL_WIDGET_GETSET_INT(textfont);
+FL_WIDGET_GETSET_INT(textsize);
+FL_WIDGET_GETSET_STR(tooltip);
+FL_WIDGET_GETSET_INT(when);
+FL_WIDGET_GETSET_INT(type);
+FL_WIDGET_INT_CALL(x);
+FL_WIDGET_INT_CALL(y);
+FL_WIDGET_INT_CALL(w);
+FL_WIDGET_INT_CALL(h);
+FL_WIDGET_VOID_CALL_2INT(position);
+FL_WIDGET_VOID_CALL_2INT(size);
+FL_WIDGET_VOID_CALL_4INT(resize);
+
+static SQInteger _flwidget_handle(HSQUIRRELVM sqvm)
+{
+    SETUP_FL_WIDGET(sqvm);
+    SQInteger event;
+    sq_getinteger(sqvm, 2, &event);
+    sq_pushinteger(sqvm, self->handle(event));
+	return 1;
+}
+
+FL_WIDGET_VOID_CALL(redraw);
+FL_WIDGET_VOID_CALL(redraw_label);
+FL_WIDGET_VOID_CALL(hide);
+FL_WIDGET_VOID_CALL(show);
+
+#define _DECL_FL_WIDGET_FUNC(name,nparams,pmask) {_SC(#name),_flwidget_##name,nparams,pmask}
+static SQRegFunction fl_widget_obj_funcs[]={
+	_DECL_FL_WIDGET_FUNC(align,-1,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(argument,-1,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(callback,-1,_SC("xc.")),
+	_DECL_FL_WIDGET_FUNC(color,-1,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(selection_color,1,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(label,-1,_SC("xs")),
+	_DECL_FL_WIDGET_FUNC(labelcolor,-1,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(labelfont,-1,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(labelsize,-1,_SC("xi")),
+	//_DECL_FL_WIDGET_FUNC(labeltype,1,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(textfont,-1,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(textsize,-1,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(tooltip,-1,_SC("xs")),
+	_DECL_FL_WIDGET_FUNC(type,-1,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(when,-1,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(handle,2,_SC("xi")),
+	_DECL_FL_WIDGET_FUNC(redraw,1,_SC("x")),
+	_DECL_FL_WIDGET_FUNC(redraw_label,1,_SC("x")),
+	_DECL_FL_WIDGET_FUNC(x,1,_SC("x")),
+	_DECL_FL_WIDGET_FUNC(y,1,_SC("x")),
+	_DECL_FL_WIDGET_FUNC(w,1,_SC("x")),
+	_DECL_FL_WIDGET_FUNC(h,1,_SC("x")),
+	_DECL_FL_WIDGET_FUNC(position,3,_SC("xii")),
+	_DECL_FL_WIDGET_FUNC(size,3,_SC("xii")),
+	_DECL_FL_WIDGET_FUNC(resize,5,_SC("xiiii")),
+	_DECL_FL_WIDGET_FUNC(show,1,_SC("x")),
+	_DECL_FL_WIDGET_FUNC(hide,1,_SC("x")),
+	{0,0}
+};
+
+class MyFl_Box : public Fl_Box {
+    public:
+    MyFl_Box(int X, int Y, int W, int H, const char *L=0):Fl_Box(X,Y,W,H,L){}
+    void draw(){
+        sq_call_fl_virtual(this, "draw");
+    }
+};
+
+FLTK_CONSTRUCTOR(MyFl_Box);
+
+static SQInteger _MyFl_Box_draw(HSQUIRRELVM sqvm)
+{
+    SETUP_FL_WIDGET(sqvm);
+    ((MyFl_Box*)self)->Fl_Box::draw();
+	return 0;
+}
+
+#define _DECL_FL_BOX_FUNC(name,nparams,pmask) {_SC(#name),_MyFl_Box_##name,nparams,pmask}
+static SQRegFunction fl_box_obj_funcs[]={
+	_DECL_FL_BOX_FUNC(constructor,-5,_SC("xiiiis")),
+	_DECL_FL_BOX_FUNC(draw,1,_SC("x")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Button);
+#define _DECL_FL_BUTTON_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Button_##name,nparams,pmask}
+static SQRegFunction fl_button_obj_funcs[]={
+	_DECL_FL_BUTTON_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Light_Button);
+#define _DECL_FL_LIGHT_BUTTON_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Light_Button_##name,nparams,pmask}
+static SQRegFunction fl_light_button_obj_funcs[]={
+	_DECL_FL_LIGHT_BUTTON_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Check_Button);
+#define _DECL_FL_CHECK_BUTTON_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Check_Button_##name,nparams,pmask}
+static SQRegFunction fl_check_button_obj_funcs[]={
+	_DECL_FL_CHECK_BUTTON_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Radio_Button);
+#define _DECL_FL_RADIO_BUTTON_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Radio_Button_##name,nparams,pmask}
+static SQRegFunction fl_radio_button_obj_funcs[]={
+	_DECL_FL_RADIO_BUTTON_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+/*
+FLTK_CONSTRUCTOR(Fl_Menu_Item);
+#define _DECL_FL_MENU_ITEM_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Menu_Item_##name,nparams,pmask}
+static SQRegFunction fl_menu_item_obj_funcs[]={
+	_DECL_FL_MENU_ITEM_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+*/
+
+FLTK_CONSTRUCTOR(Fl_Menu_);
+#define _DECL_FL_MENU__FUNC(name,nparams,pmask) {_SC(#name),_Fl_Menu__##name,nparams,pmask}
+static SQRegFunction fl_menu__obj_funcs[]={
+	_DECL_FL_MENU__FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Choice);
+#define _DECL_FL_CHOICE_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Choice_##name,nparams,pmask}
+static SQRegFunction fl_choice_obj_funcs[]={
+	_DECL_FL_CHOICE_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+
+FLTK_CONSTRUCTOR(Fl_Input_);
+#define _DECL_FL_INPUT__FUNC(name,nparams,pmask) {_SC(#name),_Fl_Input__##name,nparams,pmask}
+static SQRegFunction fl_input__obj_funcs[]={
+	_DECL_FL_INPUT__FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Input);
+#define _DECL_FL_INPUT_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Input_##name,nparams,pmask}
+static SQRegFunction fl_input_obj_funcs[]={
+	_DECL_FL_INPUT_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Float_Input);
+#define _DECL_FL_FLOAT_INPUT_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Float_Input_##name,nparams,pmask}
+static SQRegFunction fl_float_input_obj_funcs[]={
+	_DECL_FL_FLOAT_INPUT_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Int_Input);
+#define _DECL_FL_INT_INPUT_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Int_Input_##name,nparams,pmask}
+static SQRegFunction fl_int_input_obj_funcs[]={
+	_DECL_FL_INT_INPUT_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Output);
+#define _DECL_FL_INT_OUTPUT_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Output_##name,nparams,pmask}
+static SQRegFunction fl_output_obj_funcs[]={
+	_DECL_FL_INT_OUTPUT_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Secret_Input);
+#define _DECL_FL_SECRET_INPUT_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Secret_Input_##name,nparams,pmask}
+static SQRegFunction fl_secret_input_obj_funcs[]={
+	_DECL_FL_SECRET_INPUT_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+#define SETUP_FL_GROUP(v) SETUP_FL_KLASS(v, Fl_Group)
+
+FLTK_CONSTRUCTOR(Fl_Group);
+
+static SQInteger _Fl_Group_end(HSQUIRRELVM sqvm)
+{
+    SETUP_FL_GROUP(sqvm);
+    self->end();
+	return 0;
+}
+
+static SQInteger _Fl_Group_resizable(HSQUIRRELVM sqvm)
+{
+    SETUP_FL_GROUP(sqvm);
+    if(sq_gettop(sqvm)==1){
+        sq_pushuserpointer(sqvm, self->resizable());
+        return 1;
+    }
+    SQUserPointer rsz;
+    sq_getinstanceup(sqvm, -1, &rsz, 0);
+    self->resizable((Fl_Widget*)rsz);
+	return 0;
+}
+
+#define _DECL_FL_GROUP_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Group_##name,nparams,pmask}
+static SQRegFunction fl_group_obj_funcs[]={
+	_DECL_FL_GROUP_FUNC(constructor,-5,_SC("xiiiis")),
+	_DECL_FL_GROUP_FUNC(end,1,_SC("x")),
+	_DECL_FL_GROUP_FUNC(resizable,-1,_SC("xx")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Pack);
+#define _DECL_FL_PACK_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Pack_##name,nparams,pmask}
+static SQRegFunction fl_pack_obj_funcs[]={
+	_DECL_FL_PACK_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Flv_List);
+#define _DECL_FLV_LIST_FUNC(name,nparams,pmask) {_SC(#name),_Flv_List_##name,nparams,pmask}
+static SQRegFunction flv_list_obj_funcs[]={
+	_DECL_FLV_LIST_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Flv_Table);
+#define _DECL_FLV_TABLE_FUNC(name,nparams,pmask) {_SC(#name),_Flv_Table_##name,nparams,pmask}
+static SQRegFunction flv_table_obj_funcs[]={
+	_DECL_FLV_TABLE_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Tabs);
+#define _DECL_FL_TABS_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Tabs_##name,nparams,pmask}
+static SQRegFunction fl_tabs_obj_funcs[]={
+	_DECL_FL_TABS_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Text_Display);
+#define _DECL_FL_TEXT_DISPLAY_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Text_Display_##name,nparams,pmask}
+static SQRegFunction fl_text_display_obj_funcs[]={
+	_DECL_FL_TEXT_DISPLAY_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Text_Editor);
+#define _DECL_FL_TEXT_EDITOR_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Text_Editor_##name,nparams,pmask}
+static SQRegFunction fl_text_editor_obj_funcs[]={
+	_DECL_FL_TEXT_EDITOR_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+FLTK_CONSTRUCTOR(Fl_Text_Editor_Buffered);
+#define _DECL_FL_TEXT_EDITOR_BUFFERED_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Text_Editor_Buffered_##name,nparams,pmask}
+static SQRegFunction fl_text_editor_buffered_obj_funcs[]={
+	_DECL_FL_TEXT_EDITOR_BUFFERED_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+
+static SQInteger _fl_window_releasehook(SQUserPointer p, SQInteger size)
+{
+	Fl_Window *self = ((Fl_Window *)p);
+	delete self;
+	//printf("Releasing %p\n", self);
+	return 1;
+}
+
+FLTK_CONSTRUCTOR_RELEASE(Fl_Window, AS_IS, _fl_window_releasehook);
+
+#define _DECL_FL_WINDOW_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Window_##name,nparams,pmask}
+static SQRegFunction fl_window_obj_funcs[]={
+	_DECL_FL_WINDOW_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+static SQInteger _fl_double_window_releasehook(SQUserPointer p, SQInteger size)
+{
+	Fl_Double_Window *self = ((Fl_Double_Window *)p);
+	delete self;
+	//printf("Releasing %p\n", self);
+	return 1;
+}
+
+FLTK_CONSTRUCTOR_RELEASE(Fl_Double_Window, AS_IS, _fl_double_window_releasehook);
+
+#define _DECL_FL_DOUBLE_WINDOW_FUNC(name,nparams,pmask) {_SC(#name),_Fl_Double_Window_##name,nparams,pmask}
+static SQRegFunction fl_double_window_obj_funcs[]={
+	_DECL_FL_DOUBLE_WINDOW_FUNC(constructor,-5,_SC("xiiiis")),
+	{0,0}
+};
+
+static void delayedDeleteWindow(void *w){
+    printf("delayed %p\n", w);
+    Fl_Widget *win = ((Fl_Widget*)w);
+    win->hide();
+    delete win;
+}
+
+static void delWindow(Fl_Widget *sender){
+    Fl_Widget *win = sender->parent_root();
+    printf("Parent root %p\n", win);
+    Fl::add_timeout(0.1, &delayedDeleteWindow, win);
+}
+
+static Fl_Double_Window *newMyWin(){
+
+    Fl_Double_Window *win = new Fl_Double_Window(200,200, "My FLTK Window");
+    printf("New Window %p\n", win);
+
+	Fl_Button *btnNew = new Fl_Button(50,50, 80,25, "New Win");
+	btnNew->callback((Fl_Callback_p)&newMyWin);
+	Fl_Button *btnClose = new Fl_Button(50,100, 80,25, "Close Win");
+	btnClose->callback(&delWindow);
+
+    win->end();
+	win->resizable(win);
+	win->show();
+
+	return win;
+}
+
+static SQInteger _fl_show(HSQUIRRELVM sqvm)
+{
+    Fl_Double_Window *win = newMyWin();
+	sq_pushinteger(sqvm, Fl::run());
+	//delete win;
+	return 1;
+}
+
+static SQInteger _fl_run(HSQUIRRELVM sqvm)
+{
+	sq_pushinteger(sqvm, Fl::run());
+	return 1;
+}
+
+
+#define _DECL_FL_FUNC(name,nparams,pmask) {_SC(#name),_fl_##name,nparams,pmask}
+static SQRegFunction fl_obj_funcs[]={
+	_DECL_FL_FUNC(show,-1,_SC("y")),
+	_DECL_FL_FUNC(run,1,_SC("y")),
+	{0,0}
+};
+#undef _DECL_FL_FUNC
+
+static void insertFuncs(HSQUIRRELVM sqvm, SQRegFunction *obj_funcs){
+	SQInteger i = 0;
+	while(obj_funcs[i].name != 0) {
+		SQRegFunction &f = obj_funcs[i];
+		sq_pushstring(sqvm,f.name,-1);
+		sq_newclosure(sqvm,f.f,0);
+		sq_setparamscheck(sqvm,f.nparamscheck,f.typemask);
+		sq_setnativeclosurename(sqvm,-1,f.name);
+		sq_newslot(sqvm,-3,SQFalse);
+		i++;
+	}
+}
+
+#define PUSH_FL_CLASS(klass, parent, method_funcs)\
+	sq_pushstring(sqvm,_SC(#klass),-1);\
+	sq_pushstring(sqvm,_SC(#parent),-1);\
+	if (SQ_FAILED(sq_get(sqvm, -3)))\
+        return sq_throwerror(sqvm, _SC("Missing base class."));\
+	sq_newclass(sqvm,SQTrue);\
+	sq_settypetag(sqvm,-1,(void*)FLTK_TAG(klass));\
+	insertFuncs(sqvm, method_funcs);\
+	sq_newslot(sqvm,-3,SQFalse);
+
+SQRESULT sqstd_register_fltklib(HSQUIRRELVM sqvm)
+{
+    Fl::user_data = sqvm;
+	sq_pushstring(sqvm,_SC("fltk"),-1);
+	sq_newtable(sqvm);
+
+    //Fl class
+	sq_pushstring(sqvm,_SC("Fl"),-1);
+	sq_newclass(sqvm,SQFalse);
+	sq_settypetag(sqvm,-1,(void*)FLTK_TAG(Fl));
+	insertFuncs(sqvm, fl_obj_funcs);
+	sq_newslot(sqvm,-3,SQFalse);
+
+	//Fl_Widget class
+	sq_pushstring(sqvm,_SC("Fl_Widget"),-1);
+	sq_newclass(sqvm,SQFalse);
+	sq_settypetag(sqvm,-1,(void*)FLTK_TAG(Fl_Widget));
+	insertFuncs(sqvm, fl_widget_obj_funcs);
+	sq_newslot(sqvm,-3,SQFalse);
+
+	//Fl_Box class
+	PUSH_FL_CLASS(Fl_Box, Fl_Widget, fl_box_obj_funcs);
+
+	//Fl_Button class
+	PUSH_FL_CLASS(Fl_Button, Fl_Widget, fl_button_obj_funcs);
+	PUSH_FL_CLASS(Fl_Light_Button, Fl_Button, fl_light_button_obj_funcs);
+	PUSH_FL_CLASS(Fl_Check_Button, Fl_Light_Button, fl_check_button_obj_funcs);
+	PUSH_FL_CLASS(Fl_Radio_Button, Fl_Button, fl_radio_button_obj_funcs);
+
+	PUSH_FL_CLASS(Fl_Menu_, Fl_Widget, fl_menu__obj_funcs);
+	PUSH_FL_CLASS(Fl_Choice, Fl_Menu_, fl_choice_obj_funcs);
+
+	//Fl_Input_ class
+	PUSH_FL_CLASS(Fl_Input_, Fl_Widget, fl_input__obj_funcs);
+	PUSH_FL_CLASS(Fl_Input, Fl_Input_, fl_input_obj_funcs);
+	PUSH_FL_CLASS(Fl_Float_Input, Fl_Input, fl_float_input_obj_funcs);
+	PUSH_FL_CLASS(Fl_Int_Input, Fl_Input, fl_int_input_obj_funcs);
+	PUSH_FL_CLASS(Fl_Output, Fl_Input, fl_output_obj_funcs);
+	PUSH_FL_CLASS(Fl_Secret_Input, Fl_Input, fl_secret_input_obj_funcs);
+
+	//Fl_Group class
+	PUSH_FL_CLASS(Fl_Group, Fl_Widget, fl_group_obj_funcs);
+	PUSH_FL_CLASS(Fl_Pack, Fl_Group, fl_pack_obj_funcs);
+	PUSH_FL_CLASS(Fl_Tabs, Fl_Group, fl_tabs_obj_funcs);
+	PUSH_FL_CLASS(Fl_Text_Display, Fl_Group, fl_text_display_obj_funcs);
+	PUSH_FL_CLASS(Fl_Text_Editor, Fl_Text_Display, fl_text_editor_obj_funcs);
+	PUSH_FL_CLASS(Fl_Text_Editor_Buffered, Fl_Text_Editor, fl_text_editor_buffered_obj_funcs);
+
+	PUSH_FL_CLASS(Flv_List, Fl_Group, flv_list_obj_funcs);
+	PUSH_FL_CLASS(Flv_Table, Flv_List, flv_table_obj_funcs);
+
+	//Fl_Window class
+	PUSH_FL_CLASS(Fl_Window, Fl_Group, fl_window_obj_funcs);
+
+	//Fl_Double_Window class
+	PUSH_FL_CLASS(Fl_Double_Window, Fl_Window, fl_double_window_obj_funcs);
+
+	sq_newslot(sqvm,-3,SQFalse); //add fltk table to the root table
+    sq_poptop(sqvm); //removes fltk table
+
+#define INT_CONST(key) \
+    sq_pushstring(sqvm, _SC(#key), -1);\
+    sq_pushinteger(sqvm, key);\
+    sq_newslot(sqvm, -3, SQFalse);
+
+    sq_pushconsttable(sqvm);
+    INT_CONST(FL_RED);
+    INT_CONST(FL_YELLOW);
+    INT_CONST(FL_GREEN);
+    sq_poptop(sqvm);
+
+    //check to see if we need to release resources
+    Fl::do_at_widget_destroy_ = At_Widget_Destroy;
+
+	return SQ_OK;
+}
+
+#endif //WITH_FLTK

+ 15 - 0
ext/sqfltk.h

@@ -0,0 +1,15 @@
+/*	see copyright notice in squirrel.h */
+#ifndef _SQSTD_FLTK_H_
+#define _SQSTD_FLTK_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+SQUIRREL_API SQRESULT sqstd_register_fltklib(HSQUIRRELVM sqvm);
+
+#ifdef __cplusplus
+} /*extern "C"*/
+#endif
+
+#endif /*_SQSTD_FLTK_H_*/

+ 1032 - 0
ext/sqfpdf.cpp

@@ -0,0 +1,1032 @@
+#include "squirrel.h"
+#include "fpdf.h"
+#include <string.h>
+#include <stdio.h>
+
+class Sq_Fpdf : public FPDF {
+    protected:
+        HSQUIRRELVM sqvm;
+        HSQOBJECT self_weakref;
+    public:
+    Sq_Fpdf(HSQUIRRELVM v, HSQOBJECT &self):FPDF(){
+        sqvm = v;
+        self_weakref = self;
+    }
+
+    void callVirtual(const SQChar *func_name){
+        //sq_reservestack(sqvm, 20);
+        SQInteger top = sq_gettop(sqvm);
+        sq_pushobject(sqvm, self_weakref);
+        sq_pushstring(sqvm, func_name, -1);
+        sq_get(sqvm, -2);
+        if(sq_gettype(sqvm, -1) == OT_CLOSURE){
+            sq_push(sqvm, -2); //this
+            sq_call(sqvm, 1, SQFalse, SQTrue);
+        }
+        sq_settop(sqvm, top);
+    }
+
+    void Header (){
+        callVirtual(_SC("Header"));
+    };
+    void Footer () {
+        callVirtual(_SC("Footer"));
+    };
+    bool AcceptPageBreak (){
+        callVirtual(_SC("AcceptPageBreak"));
+        return FPDF::AcceptPageBreak();
+    };
+};
+
+static SQRESULT sq_glue_releasehook(SQUserPointer p, SQInteger size)
+{
+	Sq_Fpdf *self = ((Sq_Fpdf *)p);
+	delete self;
+	return 1;
+}
+
+static SQRESULT sq_glue_constructor(HSQUIRRELVM v)
+{
+    //SQ_FUNC_VARS_NO_TOP(v);
+    HSQOBJECT self;
+    sq_resetobject(&self);
+    sq_getstackobj(v, 1, &self);
+
+	Sq_Fpdf *cptr = new Sq_Fpdf(v, self);
+    sq_setinstanceup(v, 1, cptr);
+    sq_setreleasehook(v,1, sq_glue_releasehook);
+	return 1;
+}
+
+SQ_OPT_STRING_STRLEN();
+
+static const SQChar *SQ_FPDF_TAG = "Sq_Fpdf";
+
+#define GET_SQ_FPDF() SQ_GET_INSTANCE(v, 1, Sq_Fpdf, SQ_FPDF_TAG)
+
+/* bool AcceptPageBreak(  ) */
+static SQRESULT sq_glue_AcceptPageBreak(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	sq_pushbool(v, self->FPDF::AcceptPageBreak());
+	return 1;
+}
+
+/* void AddFont( char const * afamily , char const * astyle  = 0 , char const * afile  = 0 ) */
+static SQRESULT sq_glue_AddFont(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_STRING(v, 2, afamily);
+	SQ_OPT_STRING(v, 3, astyle, 0);
+	SQ_OPT_STRING(v, 4, afile, 0);
+	self->AddFont(afamily, astyle, afile);
+	return 0;
+}
+
+/* int AddLink(  ) */
+static SQRESULT sq_glue_AddLink(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	sq_pushinteger(v, self->AddLink());
+	return 1;
+}
+
+/* void AddPage( FPDF::e_orientation orientation  = FPDF::e_orientation_none , FPDF::st_pagesize * psize  = 0 ) */
+static SQRESULT sq_glue_AddPage(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_OPT_INTEGER(v, 2, orientation, FPDF::e_orientation_none);
+	SQ_OPT_STRING(v, 3, psize, 0);
+	self->AddPage((FPDF::e_orientation)orientation, 0);
+	return 0;
+}
+
+/* void AliasNbPages( char const * alias  = "{nb}" ) */
+static SQRESULT sq_glue_AliasNbPages(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_OPT_STRING(v, 2, alias, "{nb}");
+	self->AliasNbPages(alias);
+	return 0;
+}
+
+/* int CalcLines( pdf_float_t w , char const * txt ) */
+static SQRESULT sq_glue_CalcLines(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, w);
+	SQ_GET_STRING(v, 3, txt);
+	sq_pushinteger(v, self->CalcLines(w, txt));
+	return 1;
+}
+
+/* void Cell( pdf_float_t w , pdf_float_t h  = 0.0f , char const * txt  = 0 , char const * border  = 0 , int ln  = 0 , char align  = ' ' , bool fill  = false , int link  = 0 ) */
+static SQRESULT sq_glue_Cell(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, w);
+	SQ_OPT_FLOAT(v, 3, h, 0.0f);
+	SQ_OPT_STRING(v, 4, txt, 0);
+	SQ_OPT_STRING(v, 5, border, 0);
+	SQ_OPT_INTEGER(v, 6, ln, 0);
+	SQ_OPT_INTEGER(v, 7, align, ' ');
+	SQ_OPT_INTEGER(v, 8, fill, false);
+	SQ_OPT_INTEGER(v, 9, link, 0);
+	self->Cell(w, h, txt, border, ln, align, fill, link);
+	return 0;
+}
+
+/* void CellFit( pdf_float_t w , pdf_float_t h  = 0 , char const * txt  = 0 , char const * border  = 0 , int ln  = 0 , char align  = ' ' , bool fill  = false , int link  = 0 , bool scale  = false , bool force  = true ) */
+static SQRESULT sq_glue_CellFit(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, w);
+	SQ_OPT_FLOAT(v, 3, h, 0);
+	SQ_OPT_STRING(v, 4, txt, 0);
+	SQ_OPT_STRING(v, 5, border, 0);
+	SQ_OPT_INTEGER(v, 6, ln, 0);
+	SQ_OPT_INTEGER(v, 7, align, ' ');
+	SQ_OPT_INTEGER(v, 8, fill, false);
+	SQ_OPT_INTEGER(v, 9, link, 0);
+	SQ_OPT_INTEGER(v, 10, scale, false);
+	SQ_OPT_INTEGER(v, 11, force, true);
+	self->CellFit(w, h, txt, border, ln, align, fill, link, scale, force);
+	return 0;
+}
+
+/* void CellFitScale( pdf_float_t w , pdf_float_t h  = 0 , char const * txt  = 0 , char const * border  = 0 , int ln  = 0 , char align  = ' ' , bool fill  = false , int link  = 0 ) */
+static SQRESULT sq_glue_CellFitScale(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, w);
+	SQ_OPT_FLOAT(v, 3, h, 0);
+	SQ_OPT_STRING(v, 4, txt, 0);
+	SQ_OPT_STRING(v, 5, border, 0);
+	SQ_OPT_INTEGER(v, 6, ln, 0);
+	SQ_OPT_INTEGER(v, 7, align, ' ');
+	SQ_OPT_INTEGER(v, 8, fill, false);
+	SQ_OPT_INTEGER(v, 9, link, 0);
+	self->CellFitScale(w, h, txt, border, ln, align, fill, link);
+	return 0;
+}
+
+/* void CellFitScaleForce( pdf_float_t w , pdf_float_t h  = 0 , char const * txt  = 0 , char const * border  = 0 , int ln  = 0 , char align  = ' ' , bool fill  = false , int link  = 0 ) */
+static SQRESULT sq_glue_CellFitScaleForce(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, w);
+	SQ_OPT_FLOAT(v, 3, h, 0);
+	SQ_OPT_STRING(v, 4, txt, 0);
+	SQ_OPT_STRING(v, 5, border, 0);
+	SQ_OPT_INTEGER(v, 6, ln, 0);
+	SQ_OPT_INTEGER(v, 7, align, ' ');
+	SQ_OPT_INTEGER(v, 8, fill, false);
+	SQ_OPT_INTEGER(v, 9, link, 0);
+	self->CellFitScaleForce(w, h, txt, border, ln, align, fill, link);
+	return 0;
+}
+
+/* void CellFitSpace( pdf_float_t w , pdf_float_t h  = 0 , char const * txt  = 0 , char const * border  = 0 , int ln  = 0 , char align  = ' ' , bool fill  = false , int link  = 0 ) */
+static SQRESULT sq_glue_CellFitSpace(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, w);
+	SQ_OPT_FLOAT(v, 3, h, 0);
+	SQ_OPT_STRING(v, 4, txt, 0);
+	SQ_OPT_STRING(v, 5, border, 0);
+	SQ_OPT_INTEGER(v, 6, ln, 0);
+	SQ_OPT_INTEGER(v, 7, align, ' ');
+	SQ_OPT_INTEGER(v, 8, fill, false);
+	SQ_OPT_INTEGER(v, 9, link, 0);
+	self->CellFitSpace(w, h, txt, border, ln, align, fill, link);
+	return 0;
+}
+
+/* void CellFitSpaceForce( pdf_float_t w , pdf_float_t h  = 0 , char const * txt  = 0 , char const * border  = 0 , int ln  = 0 , char align  = ' ' , bool fill  = false , int link  = 0 ) */
+static SQRESULT sq_glue_CellFitSpaceForce(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, w);
+	SQ_OPT_FLOAT(v, 3, h, 0);
+	SQ_OPT_STRING(v, 4, txt, 0);
+	SQ_OPT_STRING(v, 5, border, 0);
+	SQ_OPT_INTEGER(v, 6, ln, 0);
+	SQ_OPT_INTEGER(v, 7, align, ' ');
+	SQ_OPT_INTEGER(v, 8, fill, false);
+	SQ_OPT_INTEGER(v, 9, link, 0);
+	self->CellFitSpaceForce(w, h, txt, border, ln, align, fill, link);
+	return 0;
+}
+
+/* void CheckPageBreak( pdf_float_t height ) */
+static SQRESULT sq_glue_CheckPageBreak(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, height);
+	self->CheckPageBreak(height);
+	return 0;
+}
+
+/* void Circle( pdf_float_t x , pdf_float_t y , pdf_float_t r , char const * style  = "D" ) */
+static SQRESULT sq_glue_Circle(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	SQ_GET_FLOAT(v, 3, y);
+	SQ_GET_FLOAT(v, 4, r);
+	SQ_OPT_STRING(v, 5, style, "D");
+	self->Circle(x, y, r, style);
+	return 0;
+}
+
+/* void ClippedCell( pdf_float_t w , pdf_float_t h  = 0 , char const * txt  = 0 , char const * border  = 0 , int ln  = 0 , char align  = ' ' , bool fill  = false , int link  = 0 ) */
+static SQRESULT sq_glue_ClippedCell(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, w);
+	SQ_OPT_FLOAT(v, 3, h, 0);
+	SQ_OPT_STRING(v, 4, txt, 0);
+	SQ_OPT_STRING(v, 5, border, 0);
+	SQ_OPT_INTEGER(v, 6, ln, 0);
+	SQ_OPT_INTEGER(v, 7, align, ' ');
+	SQ_OPT_INTEGER(v, 8, fill, false);
+	SQ_OPT_INTEGER(v, 9, link, 0);
+	self->ClippedCell(w, h, txt, border, ln, align, fill, link);
+	return 0;
+}
+
+/* void ClippingRect( pdf_float_t x , pdf_float_t y , pdf_float_t w , pdf_float_t h , bool outline  = false ) */
+static SQRESULT sq_glue_ClippingRect(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	SQ_GET_FLOAT(v, 3, y);
+	SQ_GET_FLOAT(v, 4, w);
+	SQ_GET_FLOAT(v, 5, h);
+	SQ_OPT_INTEGER(v, 6, outline, false);
+	self->ClippingRect(x, y, w, h, outline);
+	return 0;
+}
+
+/* void ClippingText( pdf_float_t x , pdf_float_t y , char const * txt , bool outline  = false ) */
+static SQRESULT sq_glue_ClippingText(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	SQ_GET_FLOAT(v, 3, y);
+	SQ_GET_STRING(v, 4, txt);
+	SQ_OPT_INTEGER(v, 5, outline, false);
+	self->ClippingText(x, y, txt, outline);
+	return 0;
+}
+
+/* void Close(  ) */
+static SQRESULT sq_glue_Close(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	self->Close();
+	return 0;
+}
+
+/* void Ellipse( pdf_float_t x , pdf_float_t y , pdf_float_t rx , pdf_float_t ry , char const * style  = "D" ) */
+static SQRESULT sq_glue_Ellipse(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	SQ_GET_FLOAT(v, 3, y);
+	SQ_GET_FLOAT(v, 4, rx);
+	SQ_GET_FLOAT(v, 5, ry);
+	SQ_OPT_STRING(v, 6, style, "D");
+	self->Ellipse(x, y, rx, ry, style);
+	return 0;
+}
+
+/* void Error( char const * msg ) */
+static SQRESULT sq_glue_Error(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_STRING(v, 2, msg);
+	self->Error(msg);
+	return 0;
+}
+
+/* void Footer(  ) */
+static SQRESULT sq_glue_Footer(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	self->FPDF::Footer();
+	return 0;
+}
+
+/* const & GetAliasNbPages(  ) */
+static SQRESULT sq_glue_GetAliasNbPages(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	std::string str = self->GetAliasNbPages();
+	sq_pushstring(v, str.c_str(), str.size());
+	return 1;
+}
+
+/* void GetDrawColor( FPDF::pdf_color_t & color ) */
+static SQRESULT sq_glue_GetDrawColor(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, color);
+	//self->GetDrawColor(color);
+	return 0;
+}
+
+/* void GetFillColor( FPDF::pdf_color_t & color ) */
+static SQRESULT sq_glue_GetFillColor(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, color);
+	//self->GetFillColor(color);
+	return 0;
+}
+
+/* void GetFontSettings( font_settings_st & fs ) */
+static SQRESULT sq_glue_GetFontSettings(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, fs);
+	//self->GetFontSettings(fs);
+	return 0;
+}
+
+/* pdf_float_t GetFontSize(  ) */
+static SQRESULT sq_glue_GetFontSize(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	sq_pushfloat(v, self->GetFontSize());
+	return 1;
+}
+
+/* pdf_float_t GetH(  ) */
+static SQRESULT sq_glue_GetH(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	sq_pushfloat(v, self->GetH());
+	return 1;
+}
+
+/* pdf_float_t GetLeftMargin(  ) */
+static SQRESULT sq_glue_GetLeftMargin(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	sq_pushfloat(v, self->GetLeftMargin());
+	return 1;
+}
+
+/* pdf_float_t GetRightMargin(  ) */
+static SQRESULT sq_glue_GetRightMargin(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	sq_pushfloat(v, self->GetRightMargin());
+	return 1;
+}
+
+/* pdf_float_t GetStringWidth( char const * s ) */
+static SQRESULT sq_glue_GetStringWidth(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_STRING(v, 2, s);
+	sq_pushfloat(v, self->GetStringWidth(s));
+	return 1;
+}
+
+/* void GetTextColor( FPDF::pdf_color_t & color ) */
+static SQRESULT sq_glue_GetTextColor(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, color);
+	//self->GetTextColor(color);
+	return 0;
+}
+
+/* pdf_float_t GetW(  ) */
+static SQRESULT sq_glue_GetW(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	sq_pushfloat(v, self->GetW());
+	return 1;
+}
+
+/* pdf_float_t GetX(  ) */
+static SQRESULT sq_glue_GetX(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	sq_pushfloat(v, self->GetX());
+	return 1;
+}
+
+/* pdf_float_t GetY(  ) */
+static SQRESULT sq_glue_GetY(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	sq_pushfloat(v, self->GetY());
+	return 1;
+}
+
+/* void Header(  ) */
+static SQRESULT sq_glue_Header(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	self->FPDF::Header();
+	return 0;
+}
+
+/* void Image( char const * file , pdf_float_t x  = -1 , pdf_float_t y  = -1 , pdf_float_t w  = 0.0 , pdf_float_t h  = 0.0 , char const * atype  = 0 , int link  = 0 ) */
+static SQRESULT sq_glue_Image(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_STRING(v, 2, file);
+	SQ_OPT_FLOAT(v, 3, x, -1);
+	SQ_OPT_FLOAT(v, 4, y, -1);
+	SQ_OPT_FLOAT(v, 5, w, 0.0);
+	SQ_OPT_FLOAT(v, 6, h, 0.0);
+	SQ_OPT_STRING(v, 7, atype, 0);
+	SQ_OPT_INTEGER(v, 8, link, 0);
+	self->Image(file, x, y, w, h, atype, link);
+	return 0;
+}
+
+/* void IncludeJS( char const * script ) */
+static SQRESULT sq_glue_IncludeJS(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_STRING(v, 2, script);
+	self->IncludeJS(script);
+	return 0;
+}
+
+/* void Line( pdf_float_t x1 , pdf_float_t y1 , pdf_float_t x2 , pdf_float_t y2 ) */
+static SQRESULT sq_glue_Line(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x1);
+	SQ_GET_FLOAT(v, 3, y1);
+	SQ_GET_FLOAT(v, 4, x2);
+	SQ_GET_FLOAT(v, 5, y2);
+	self->Line(x1, y1, x2, y2);
+	return 0;
+}
+
+/* void Link( pdf_float_t x , pdf_float_t y , pdf_float_t w , pdf_float_t h , int link ) */
+static SQRESULT sq_glue_Link(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	SQ_GET_FLOAT(v, 3, y);
+	SQ_GET_FLOAT(v, 4, w);
+	SQ_GET_FLOAT(v, 5, h);
+	SQ_GET_INTEGER(v, 6, link);
+	self->Link(x, y, w, h, link);
+	return 0;
+}
+
+/* void Ln( pdf_float_t h  = 0.0 ) */
+static SQRESULT sq_glue_Ln(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_OPT_FLOAT(v, 2, h, 0.0);
+	self->Ln(h);
+	return 0;
+}
+
+/* void MultiCell( pdf_float_t w , pdf_float_t h , char const * txt , char const * border  = 0 , char align  = 'J' , bool fill  = false ) */
+static SQRESULT sq_glue_MultiCell(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, w);
+	SQ_GET_FLOAT(v, 3, h);
+	SQ_GET_STRING(v, 4, txt);
+	SQ_OPT_STRING(v, 5, border, 0);
+	SQ_OPT_INTEGER(v, 6, align, 'J');
+	SQ_OPT_INTEGER(v, 7, fill, false);
+	self->MultiCell(w, h, txt, border, align, fill);
+	return 0;
+}
+
+/* void MultiCellBlt( pdf_float_t w , pdf_float_t h , char const * blt , char const * txt , char const * border  = 0 , char align  = 'J' , bool fill  = false ) */
+static SQRESULT sq_glue_MultiCellBlt(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, w);
+	SQ_GET_FLOAT(v, 3, h);
+	SQ_GET_STRING(v, 4, blt);
+	SQ_GET_STRING(v, 5, txt);
+	SQ_OPT_STRING(v, 6, border, 0);
+	SQ_OPT_INTEGER(v, 7, align, 'J');
+	SQ_OPT_INTEGER(v, 8, fill, false);
+	self->MultiCellBlt(w, h, blt, txt, border, align, fill);
+	return 0;
+}
+
+/* void Open(  ) */
+static SQRESULT sq_glue_Open(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	self->Open();
+	return 0;
+}
+
+/* string Output( char const * name  = 0 , char dest  = ' ' ) */
+static SQRESULT sq_glue_Output(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_OPT_STRING(v, 2, name, 0);
+	SQ_OPT_INTEGER(v, 3, dest, ' ');
+	std::string str = self->Output(name, dest);
+	sq_pushstring(v, str.c_str(), str.size());
+	return 1;
+}
+
+/* int PageNo(  ) */
+static SQRESULT sq_glue_PageNo(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	sq_pushinteger(v, self->PageNo());
+	return 1;
+}
+
+/* void Rect( pdf_float_t x , pdf_float_t y , pdf_float_t w , pdf_float_t h , char const * style  = 0 ) */
+static SQRESULT sq_glue_Rect(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	SQ_GET_FLOAT(v, 3, y);
+	SQ_GET_FLOAT(v, 4, w);
+	SQ_GET_FLOAT(v, 5, h);
+	SQ_OPT_STRING(v, 6, style, 0);
+	self->Rect(x, y, w, h, style);
+	return 0;
+}
+
+/* void Rotate( pdf_float_t angle , pdf_float_t x  = -1 , pdf_float_t y  = -1 ) */
+static SQRESULT sq_glue_Rotate(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, angle);
+	SQ_OPT_FLOAT(v, 3, x, -1);
+	SQ_OPT_FLOAT(v, 4, y, -1);
+	self->Rotate(angle, x, y);
+	return 0;
+}
+
+/* void RotatedText( pdf_float_t x , pdf_float_t y , char const * txt , pdf_float_t angle ) */
+static SQRESULT sq_glue_RotatedText(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	SQ_GET_FLOAT(v, 3, y);
+	SQ_GET_STRING(v, 4, txt);
+	SQ_GET_FLOAT(v, 5, angle);
+	self->RotatedText(x, y, txt, angle);
+	return 0;
+}
+
+/* void RoundedRect( pdf_float_t x , pdf_float_t y , pdf_float_t w , pdf_float_t h , pdf_float_t r , char const * style  = "" ) */
+static SQRESULT sq_glue_RoundedRect(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	SQ_GET_FLOAT(v, 3, y);
+	SQ_GET_FLOAT(v, 4, w);
+	SQ_GET_FLOAT(v, 5, h);
+	SQ_GET_FLOAT(v, 6, r);
+	SQ_OPT_STRING(v, 7, style, "");
+	self->RoundedRect(x, y, w, h, r, style);
+	return 0;
+}
+
+/* void SetAlpha( pdf_float_t alpha , char const * bm  = 0 ) */
+static SQRESULT sq_glue_SetAlpha(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, alpha);
+	SQ_OPT_STRING(v, 3, bm, 0);
+	self->SetAlpha(alpha, bm);
+	return 0;
+}
+
+/* void SetAuthor( char const * author ) */
+static SQRESULT sq_glue_SetAuthor(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_STRING(v, 2, author);
+	self->SetAuthor(author);
+	return 0;
+}
+
+/* void SetAutoPageBreak( bool b , pdf_float_t margin  = 0.0f ) */
+static SQRESULT sq_glue_SetAutoPageBreak(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, b);
+	SQ_OPT_FLOAT(v, 3, margin, 0.0f);
+	self->SetAutoPageBreak(b, margin);
+	return 0;
+}
+
+/* void SetCompression( bool compress ) */
+static SQRESULT sq_glue_SetCompression(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_BOOL(v, 2, compress);
+	self->SetCompression(compress);
+	return 0;
+}
+
+/* void SetCreator( char const * creator ) */
+static SQRESULT sq_glue_SetCreator(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_STRING(v, 2, creator);
+	self->SetCreator(creator);
+	return 0;
+}
+
+/* void SetDash( pdf_float_t black  = -1 , pdf_float_t white  = -1 ) */
+static SQRESULT sq_glue_SetDash(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_OPT_FLOAT(v, 2, black, -1);
+	SQ_OPT_FLOAT(v, 3, white, -1);
+	self->SetDash(black, white);
+	return 0;
+}
+
+/* void SetDisplayMode( FPDF::e_zoom_mode zoom , FPDF::e_layout_mode layout  = FPDF::e_layout_default ) */
+static SQRESULT sq_glue_SetDisplayMode(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, zoom);
+	SQ_OPT_INTEGER(v, 3, layout, FPDF::e_layout_default);
+	//self->SetDisplayMode(zoom, layout);
+	return 0;
+}
+
+/* void SetDoubleSided( pdf_float_t inner  = 7 , pdf_float_t outer  = 13 ) */
+static SQRESULT sq_glue_SetDoubleSided(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_OPT_FLOAT(v, 2, inner, 7);
+	SQ_OPT_FLOAT(v, 3, outer, 13);
+	self->SetDoubleSided(inner, outer);
+	return 0;
+}
+
+/* void SetDrawColor( unsigned char r , unsigned char g , unsigned char b ) */
+static SQRESULT sq_glue_SetDrawColor(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, r);
+	SQ_GET_INTEGER(v, 3, g);
+	SQ_GET_INTEGER(v, 4, b);
+	self->SetDrawColor(r, g, b);
+	return 0;
+}
+
+/* void SetFillColor( unsigned char r , unsigned char g , unsigned char b ) */
+static SQRESULT sq_glue_SetFillColor(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, r);
+	SQ_GET_INTEGER(v, 3, g);
+	SQ_GET_INTEGER(v, 4, b);
+	self->SetFillColor(r, g, b);
+	return 0;
+}
+
+/* void SetFont( char const * afamily  = 0 , char const * astyle  = 0 , pdf_float_t size  = 0 ) */
+static SQRESULT sq_glue_SetFont(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_OPT_STRING(v, 2, afamily, 0);
+	SQ_OPT_STRING(v, 3, astyle, 0);
+	SQ_OPT_FLOAT(v, 4, size, 0);
+	self->SetFont(afamily, astyle, size);
+	return 0;
+}
+
+/* void SetFontSettings( font_settings_st & fs ) */
+static SQRESULT sq_glue_SetFontSettings(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, fs);
+	//self->SetFontSettings(fs);
+	return 0;
+}
+
+/* void SetFontSize( pdf_float_t size ) */
+static SQRESULT sq_glue_SetFontSize(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, size);
+	self->SetFontSize(size);
+	return 0;
+}
+
+/* void SetKeywords( char const * keywords ) */
+static SQRESULT sq_glue_SetKeywords(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_STRING(v, 2, keywords);
+	self->SetKeywords(keywords);
+	return 0;
+}
+
+/* void SetLeftMargin( pdf_float_t margin ) */
+static SQRESULT sq_glue_SetLeftMargin(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, margin);
+	self->SetLeftMargin(margin);
+	return 0;
+}
+
+/* void SetLineWidth( pdf_float_t width ) */
+static SQRESULT sq_glue_SetLineWidth(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, width);
+	self->SetLineWidth(width);
+	return 0;
+}
+
+/* void SetLink( int link , pdf_float_t y  = 0 , int page  = -1 ) */
+static SQRESULT sq_glue_SetLink(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, link);
+	SQ_OPT_FLOAT(v, 3, y, 0);
+	SQ_OPT_INTEGER(v, 4, page, -1);
+	self->SetLink(link, y, page);
+	return 0;
+}
+
+/* void SetMargins( pdf_float_t left , pdf_float_t top , pdf_float_t right  = 0.0f ) */
+static SQRESULT sq_glue_SetMargins(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, left);
+	SQ_GET_FLOAT(v, 3, top);
+	SQ_OPT_FLOAT(v, 4, right, 0.0f);
+	self->SetMargins(left, top, right);
+	return 0;
+}
+
+/* void SetRightMargin( pdf_float_t margin ) */
+static SQRESULT sq_glue_SetRightMargin(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, margin);
+	self->SetRightMargin(margin);
+	return 0;
+}
+
+/* void SetSubject( char const * subject ) */
+static SQRESULT sq_glue_SetSubject(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_STRING(v, 2, subject);
+	self->SetSubject(subject);
+	return 0;
+}
+
+/* void SetTextColor( unsigned char r , unsigned char g , unsigned char b ) */
+static SQRESULT sq_glue_SetTextColor(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, r);
+	SQ_GET_INTEGER(v, 3, g);
+	SQ_GET_INTEGER(v, 4, b);
+	self->SetTextColor(r, g, b);
+	return 0;
+}
+
+/* void SetTitle( char const * title ) */
+static SQRESULT sq_glue_SetTitle(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_STRING(v, 2, title);
+	self->SetTitle(title);
+	return 0;
+}
+
+/* void SetTopMargin( pdf_float_t margin ) */
+static SQRESULT sq_glue_SetTopMargin(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, margin);
+	self->SetTopMargin(margin);
+	return 0;
+}
+
+/* void SetX( pdf_float_t x ) */
+static SQRESULT sq_glue_SetX(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	self->SetX(x);
+	return 0;
+}
+
+/* void SetXY( pdf_float_t x , pdf_float_t y ) */
+static SQRESULT sq_glue_SetXY(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	SQ_GET_FLOAT(v, 3, y);
+	self->SetXY(x, y);
+	return 0;
+}
+
+/* void SetY( pdf_float_t y ) */
+static SQRESULT sq_glue_SetY(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, y);
+	self->SetY(y);
+	return 0;
+}
+
+/* void Text( pdf_float_t x , pdf_float_t y , char const * txt ) */
+static SQRESULT sq_glue_Text(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	SQ_GET_FLOAT(v, 3, y);
+	SQ_GET_STRING(v, 4, txt);
+	self->Text(x, y, txt);
+	return 0;
+}
+
+/* void TextShadow( pdf_float_t x , pdf_float_t y , char const * txt , pdf_float_t displacement  = .3 ) */
+static SQRESULT sq_glue_TextShadow(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, x);
+	SQ_GET_FLOAT(v, 3, y);
+	SQ_GET_STRING(v, 4, txt);
+	SQ_OPT_FLOAT(v, 5, displacement, .3);
+	self->TextShadow(x, y, txt, displacement);
+	return 0;
+}
+
+/* void UnsetClipping(  ) */
+static SQRESULT sq_glue_UnsetClipping(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	self->UnsetClipping();
+	return 0;
+}
+
+/* void Write( pdf_float_t h , char const * txt , int link  = 0 ) */
+static SQRESULT sq_glue_Write(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_GET_FLOAT(v, 2, h);
+	SQ_GET_STRING(v, 3, txt);
+	SQ_OPT_INTEGER(v, 4, link, 0);
+	self->Write(h, txt, link);
+	return 0;
+}
+
+/* int getCustomZoom(  ) */
+static SQRESULT sq_glue_getCustomZoom(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	sq_pushinteger(v, self->getCustomZoom());
+	return 1;
+}
+
+/* void reset( FPDF::e_orientation orientation  = FPDF::e_orientation_portrait , FPDF::e_units unit  = FPDF::e_mm , FPDF::e_page_sizes psize  = FPDF::e_A4 ) */
+static SQRESULT sq_glue_reset(HSQUIRRELVM v){
+	SQ_FUNC_VARS(v);
+	GET_SQ_FPDF();
+	SQ_OPT_INTEGER(v, 2, orientation, FPDF::e_orientation_portrait);
+	SQ_OPT_INTEGER(v, 3, unit, FPDF::e_mm);
+	SQ_OPT_INTEGER(v, 4, psize, FPDF::e_A4);
+	//self->reset(orientation, unit, psize);
+	return 0;
+}
+
+/* void setCustomZoom( int zoom ) */
+static SQRESULT sq_glue_setCustomZoom(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQ_FPDF();
+	SQ_GET_INTEGER(v, 2, zoom);
+	self->setCustomZoom(zoom);
+	return 0;
+}
+
+#define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),  sq_glue_##name,nparams,tycheck}
+static SQRegFunction sq_glue_my_methods[] =
+{
+	_DECL_FUNC(constructor,  1, _SC("x")),
+	_DECL_FUNC(AcceptPageBreak,  1, _SC("x")),
+	_DECL_FUNC(AddFont,  -2, _SC("xsss")),
+	_DECL_FUNC(AddLink,  1, _SC("x")),
+	_DECL_FUNC(AddPage,  -1, _SC("xis")),
+	_DECL_FUNC(AliasNbPages,  -1, _SC("xs")),
+	_DECL_FUNC(CalcLines,  3, _SC("xns")),
+	_DECL_FUNC(Cell,  -2, _SC("xnnssiiii")),
+	_DECL_FUNC(CellFit,  -2, _SC("xnnssiiiiii")),
+	_DECL_FUNC(CellFitScale,  -2, _SC("xnnssiiii")),
+	_DECL_FUNC(CellFitScaleForce,  -2, _SC("xnnssiiii")),
+	_DECL_FUNC(CellFitSpace,  -2, _SC("xnnssiiii")),
+	_DECL_FUNC(CellFitSpaceForce,  -2, _SC("xnnssiiii")),
+	_DECL_FUNC(CheckPageBreak,  2, _SC("xn")),
+	_DECL_FUNC(Circle,  -4, _SC("xnnns")),
+	_DECL_FUNC(ClippedCell,  -2, _SC("xnnssiiii")),
+	_DECL_FUNC(ClippingRect,  -5, _SC("xnnnni")),
+	_DECL_FUNC(ClippingText,  -4, _SC("xnnsi")),
+	_DECL_FUNC(Close,  1, _SC("x")),
+	_DECL_FUNC(Ellipse,  -5, _SC("xnnnns")),
+	_DECL_FUNC(Error,  2, _SC("xs")),
+	_DECL_FUNC(Footer,  1, _SC("x")),
+	_DECL_FUNC(GetAliasNbPages,  1, _SC("x")),
+	_DECL_FUNC(GetDrawColor,  2, _SC("xi")),
+	_DECL_FUNC(GetFillColor,  2, _SC("xi")),
+	_DECL_FUNC(GetFontSettings,  2, _SC("xi")),
+	_DECL_FUNC(GetFontSize,  1, _SC("x")),
+	_DECL_FUNC(GetH,  1, _SC("x")),
+	_DECL_FUNC(GetLeftMargin,  1, _SC("x")),
+	_DECL_FUNC(GetRightMargin,  1, _SC("x")),
+	_DECL_FUNC(GetStringWidth,  2, _SC("xs")),
+	_DECL_FUNC(GetStringWidth,  2, _SC("xi")),
+	_DECL_FUNC(GetTextColor,  2, _SC("xi")),
+	_DECL_FUNC(GetW,  1, _SC("x")),
+	_DECL_FUNC(GetX,  1, _SC("x")),
+	_DECL_FUNC(GetY,  1, _SC("x")),
+	_DECL_FUNC(Header,  1, _SC("x")),
+	_DECL_FUNC(Image,  -2, _SC("xsnnnnsi")),
+	_DECL_FUNC(IncludeJS,  2, _SC("xs")),
+	_DECL_FUNC(Line,  5, _SC("xnnnn")),
+	_DECL_FUNC(Link,  6, _SC("xnnnni")),
+	_DECL_FUNC(Ln,  -1, _SC("xn")),
+	_DECL_FUNC(MultiCell,  -4, _SC("xnnssii")),
+	_DECL_FUNC(MultiCellBlt,  -5, _SC("xnnsssii")),
+	_DECL_FUNC(Open,  1, _SC("x")),
+	_DECL_FUNC(Output,  -1, _SC("xsi")),
+	_DECL_FUNC(PageNo,  1, _SC("x")),
+	_DECL_FUNC(Rect,  -5, _SC("xnnnns")),
+	_DECL_FUNC(Rotate,  -2, _SC("xnnn")),
+	_DECL_FUNC(RotatedText,  5, _SC("xnnsn")),
+	_DECL_FUNC(RoundedRect,  -6, _SC("xnnnnns")),
+	_DECL_FUNC(SetAlpha,  -2, _SC("xns")),
+	_DECL_FUNC(SetAuthor,  2, _SC("xs")),
+	_DECL_FUNC(SetAutoPageBreak,  -2, _SC("xin")),
+	_DECL_FUNC(SetCompression,  2, _SC("xb")),
+	_DECL_FUNC(SetCreator,  2, _SC("xs")),
+	_DECL_FUNC(SetDash,  -1, _SC("xnn")),
+	_DECL_FUNC(SetDisplayMode,  -2, _SC("xii")),
+	_DECL_FUNC(SetDoubleSided,  -1, _SC("xnn")),
+	_DECL_FUNC(SetDrawColor,  -2, _SC("xiii")),
+	_DECL_FUNC(SetFillColor,  -2, _SC("xiii")),
+	_DECL_FUNC(SetFont,  -1, _SC("xssn")),
+	_DECL_FUNC(SetFontSettings,  2, _SC("xi")),
+	_DECL_FUNC(SetFontSize,  2, _SC("xn")),
+	_DECL_FUNC(SetKeywords,  2, _SC("xs")),
+	_DECL_FUNC(SetLeftMargin,  2, _SC("xn")),
+	_DECL_FUNC(SetLineWidth,  2, _SC("xn")),
+	_DECL_FUNC(SetLink,  -2, _SC("xini")),
+	_DECL_FUNC(SetMargins,  -3, _SC("xnnn")),
+	_DECL_FUNC(SetRightMargin,  2, _SC("xn")),
+	_DECL_FUNC(SetSubject,  2, _SC("xs")),
+	_DECL_FUNC(SetTextColor,  -2, _SC("xiii")),
+	_DECL_FUNC(SetTitle,  2, _SC("xs")),
+	_DECL_FUNC(SetTopMargin,  2, _SC("xn")),
+	_DECL_FUNC(SetX,  2, _SC("xn")),
+	_DECL_FUNC(SetXY,  3, _SC("xnn")),
+	_DECL_FUNC(SetY,  2, _SC("xn")),
+	_DECL_FUNC(Text,  4, _SC("xnns")),
+	_DECL_FUNC(TextShadow,  -4, _SC("xnnsn")),
+	_DECL_FUNC(UnsetClipping,  1, _SC("x")),
+	_DECL_FUNC(Write,  -3, _SC("xnsi")),
+	_DECL_FUNC(getCustomZoom,  1, _SC("x")),
+	_DECL_FUNC(reset,  -1, _SC("xiii")),
+	_DECL_FUNC(setCustomZoom,  2, _SC("xi")),
+	{0,0}
+};
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    SQRESULT sqstd_register_Sq_Fpdf(HSQUIRRELVM v)
+    {
+        sq_pushstring(v,SQ_FPDF_TAG,-1);
+        sq_newclass(v,SQFalse);
+        sq_settypetag(v,-1,(void*)SQ_FPDF_TAG);
+        sq_insert_reg_funcs(v, sq_glue_my_methods);
+        sq_newslot(v,-3,SQTrue);
+        return 1;
+    }
+
+#ifdef __cplusplus
+}
+#endif