using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.InteropServices;

namespace BIXOLON_Sample_program
{
    class BXLLIB
    {
        public static string m_strProcessor = "";
        public static bool Is64Bit()
        {
            if( m_strProcessor.Length == 0 )
                m_strProcessor = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");

            if (m_strProcessor == "x86")
                return false;

            return true;
        }

        //////////////////////////////////////////////////////////////////////
        //  Function List
        //////////////////////////////////////////////////////////////////////

        public static bool ConnectPrinter(string strPrinterName)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.ConnectPrinter(strPrinterName);
            }
            else
            {
                return BXLLIB_x86.ConnectPrinter(strPrinterName);
            }
        }

        public static bool DisconnectPrinter()
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.DisconnectPrinter();
            }
            else
            {
                return BXLLIB_x86.DisconnectPrinter();
            }
        }

        public static bool StartLabel()
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.StartLabel();
            }
            else
            {
                return BXLLIB_x86.StartLabel();
            }
        }

        public static void EndLabel()
        {
            if (Is64Bit())
            {
                BXLLIB_x64.EndLabel();
            }
            else
            {
                BXLLIB_x86.EndLabel();
            }
        }

        public static int GetPrinterResolution()
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.GetPrinterResolution();
            }
            else
            {
                return BXLLIB_x86.GetPrinterResolution();
            }
        }

        public static int GetBIXOLON_PrinterList(StringBuilder strBxlPrtList)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.GetBIXOLON_PrinterList(strBxlPrtList);
            }
            else
            {
                return BXLLIB_x86.GetBIXOLON_PrinterList(strBxlPrtList);
            }
        }

        public static bool GetDllVersion(StringBuilder strDllVersion)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.GetDllVersion(strDllVersion);
            }
            else
            {
                return BXLLIB_x86.GetDllVersion(strDllVersion);
            }
        }


        public static bool Print1DBarcode(int nHorizontalPos, int nVerticalPos, int nBarcodeType, int nNarrowBarWidth, int nWideBarWidth, int nBarcodeHeight, int nRotation, int nHRI, string pData)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.Print1DBarcode(nHorizontalPos, nVerticalPos, nBarcodeType, nNarrowBarWidth, nWideBarWidth, nBarcodeHeight, nRotation, nHRI, pData);
            }
            else
            {
                return BXLLIB_x86.Print1DBarcode(nHorizontalPos, nVerticalPos, nBarcodeType, nNarrowBarWidth, nWideBarWidth, nBarcodeHeight, nRotation, nHRI, pData);
            }
        }

        public static bool PrintDeviceFont(int nHorizontalPos, int nVerticalPos, int nFontName, int nHorizontalMulti, int nVerticalMulti, int nRotation, bool bBold, string szText)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintDeviceFont(nHorizontalPos, nVerticalPos, nFontName, nHorizontalMulti, nVerticalMulti, nRotation, bBold, szText);
            }
            else
            {
                return BXLLIB_x86.PrintDeviceFont(nHorizontalPos, nVerticalPos, nFontName, nHorizontalMulti, nVerticalMulti, nRotation, bBold, szText);
            }
        }

        public static bool PrintDeviceFontW(int nHorizontalPos, int nVerticalPos, int nFontName, int nHorizontalMulti, int nVerticalMulti, int nRotation, bool bBold, string szText, int nCodePage)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintDeviceFontW(nHorizontalPos, nVerticalPos, nFontName, nHorizontalMulti, nVerticalMulti, nRotation, bBold, szText, nCodePage);
            }
            else
            {
                return BXLLIB_x86.PrintDeviceFontW(nHorizontalPos, nVerticalPos, nFontName, nHorizontalMulti, nVerticalMulti, nRotation, bBold, szText, nCodePage);
            }
        }

        public static bool SetConfigOfPrinter(int nSpeed, int nDensity, int nOrientation, bool bAutoCut, int nCuttingPeriod, bool bBackFeeding)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.SetConfigOfPrinter(nSpeed, nDensity, nOrientation, bAutoCut, nCuttingPeriod, bBackFeeding);
            }
            else
            {
                return BXLLIB_x86.SetConfigOfPrinter(nSpeed, nDensity, nOrientation, bAutoCut, nCuttingPeriod, bBackFeeding);
            }
        }


        public static bool Prints(int nLabelSet, int nCopiesOfEachLabel)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.Prints(nLabelSet, nCopiesOfEachLabel);
            }
            else
            {
                return BXLLIB_x86.Prints(nLabelSet, nCopiesOfEachLabel);
            }
        }


        public static bool SetPaper(int nHorizontalMagin, int nVerticalMargin, int nPaperWidth, int nPaperLength, int nMediaType, int nOffSet, int nGapLengthORThicknessOfBlackLine)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.SetPaper(nHorizontalMagin, nVerticalMargin, nPaperWidth, nPaperLength, nMediaType, nOffSet, nGapLengthORThicknessOfBlackLine);
            }
            else
            {
                return BXLLIB_x86.SetPaper(nHorizontalMagin, nVerticalMargin, nPaperWidth, nPaperLength, nMediaType, nOffSet, nGapLengthORThicknessOfBlackLine);
            }
        }

        public static bool ClearBuffer()
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.ClearBuffer();
            }
            else
            {
                return BXLLIB_x86.ClearBuffer();
            }
        }


        public static bool PrintBlock(int nHorizontalStartPos, int nVerticalStartPos, int nHorizontalEndPos, int nVerticalEndPos, int nOption, int nThickness)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintBlock(nHorizontalStartPos, nVerticalStartPos, nHorizontalEndPos, nVerticalEndPos, nOption, nThickness);
            }
            else
            {
                return BXLLIB_x86.PrintBlock(nHorizontalStartPos, nVerticalStartPos, nHorizontalEndPos, nVerticalEndPos, nOption, nThickness);
            }
        }


        public static bool PrintCircle(int nHorizontalStartPos, int nVerticalStartPos, int nDiameter, int nMulti)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintCircle(nHorizontalStartPos, nVerticalStartPos, nDiameter, nMulti);
            }
            else
            {
                return BXLLIB_x86.PrintCircle(nHorizontalStartPos, nVerticalStartPos, nDiameter, nMulti);
            }
        }


        public static bool PrintDirect(string pDirectData, bool bAddCrLf)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintDirect(pDirectData, bAddCrLf);
            }
            else
            {
                return BXLLIB_x86.PrintDirect(pDirectData, bAddCrLf);
            }
        }

        public static bool WriteBuffer(string pDirectData, int nDataLength)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.WriteBuffer(pDirectData, nDataLength);
            }
            else
            {
                return BXLLIB_x86.WriteBuffer(pDirectData, nDataLength);
            }
        }

        public static bool PrintTrueFont(int nXPos, int nYPos, string strFontName, int nFontSize, int nRotaion, bool bItalic, bool bBold, bool bUnderline, string strText, bool bDataCompression)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintTrueFont(nXPos, nYPos, strFontName, nFontSize, nRotaion, bItalic, bBold, bUnderline, strText, bDataCompression);
            }
            else
            {
                return BXLLIB_x86.PrintTrueFont(nXPos, nYPos, strFontName, nFontSize, nRotaion, bItalic, bBold, bUnderline, strText, bDataCompression);
            }
        }

        public static bool PrintTrueFontW(int nXPos, int nYPos, string strFontName, int nFontSize, int nRotaion, bool bItalic, bool bBold, bool bUnderline, string strText, bool bDataCompression)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintTrueFontW(nXPos, nYPos, strFontName, nFontSize, nRotaion, bItalic, bBold, bUnderline, strText, bDataCompression);
            }
            else
            {
                return BXLLIB_x86.PrintTrueFontW(nXPos, nYPos, strFontName, nFontSize, nRotaion, bItalic, bBold, bUnderline, strText, bDataCompression);
            }
        }

        public static bool PrintTrueFontLib(int nXPos, int nYPos, string strFontName, int nFontSize, int nRotaion, bool bItalic, bool bBold, bool bUnderline, string strText, bool bDataCompression)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintTrueFontLib(nXPos, nYPos, strFontName, nFontSize, nRotaion, bItalic, bBold, bUnderline, strText, bDataCompression);
            }
            else
            {
                return BXLLIB_x86.PrintTrueFontLib(nXPos, nYPos, strFontName, nFontSize, nRotaion, bItalic, bBold, bUnderline, strText, bDataCompression);
            }
        }

        public static bool PrintTrueFontLibW(int nXPos, int nYPos, string strFontName, int nFontSize, int nRotaion, bool bItalic, bool bBold, bool bUnderline, string strText, bool bDataCompression)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintTrueFontLibW(nXPos, nYPos, strFontName, nFontSize, nRotaion, bItalic, bBold, bUnderline, strText, bDataCompression);
            }
            else
            {
                return BXLLIB_x86.PrintTrueFontLibW(nXPos, nYPos, strFontName, nFontSize, nRotaion, bItalic, bBold, bUnderline, strText, bDataCompression);
            }
        }


        public static bool PrintVectorFont(int nXPos, int nYPos, string FontSelection, int FontWidth, int FontHeight, string RightSideCharSpacing, bool bBold, bool ReversePrinting, bool TextStyle, int Rotation, string TextAlignment, int TextDirection, string pData)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintVectorFont(nXPos, nYPos, FontSelection, FontWidth, FontHeight, RightSideCharSpacing, bBold, ReversePrinting, TextStyle, Rotation, TextAlignment, TextDirection, pData);
            }
            else
            {
                return BXLLIB_x86.PrintVectorFont(nXPos, nYPos, FontSelection, FontWidth, FontHeight, RightSideCharSpacing, bBold, ReversePrinting, TextStyle, Rotation, TextAlignment, TextDirection, pData);
            }
        }

        public static bool PrintVectorFontW(int nXPos, int nYPos, string FontSelection, int FontWidth, int FontHeight, string RightSideCharSpacing, bool bBold, bool ReversePrinting, bool TextStyle, int Rotation, string TextAlignment, int TextDirection, string pData, int nCodePage)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintVectorFontW(nXPos, nYPos, FontSelection, FontWidth, FontHeight, RightSideCharSpacing, bBold, ReversePrinting, TextStyle, Rotation, TextAlignment, TextDirection, pData, nCodePage);
            }
            else
            {
                return BXLLIB_x86.PrintVectorFontW(nXPos, nYPos, FontSelection, FontWidth, FontHeight, RightSideCharSpacing, bBold, ReversePrinting, TextStyle, Rotation, TextAlignment, TextDirection, pData, nCodePage);
            }
        }

        public static bool PrintQRCode(int nXPos, int nYPos, int nModel, int nECCLevel, int nSize, int nRotation, string pData)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintQRCode(nXPos, nYPos, nModel, nECCLevel, nSize, nRotation, pData);
            }
            else
            {
                return BXLLIB_x86.PrintQRCode(nXPos, nYPos, nModel, nECCLevel, nSize, nRotation, pData);
            }
        }

        public static bool PrintImageLib(int nHorizontalStartPos, int nVerticalStartPos, string pBitmapFilename, int nDither, bool bDataCompression)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintImageLib(nHorizontalStartPos, nVerticalStartPos, pBitmapFilename, nDither, bDataCompression);
            }
            else
            {
                return BXLLIB_x86.PrintImageLib(nHorizontalStartPos, nVerticalStartPos, pBitmapFilename, nDither, bDataCompression);
            }
        }

        public static bool PrintImageLibW(int nHorizontalStartPos, int nVerticalStartPos, string pBitmapFilename, int nDither, bool bDataCompression)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.PrintImageLibW(nHorizontalStartPos, nVerticalStartPos, pBitmapFilename, nDither, bDataCompression);
            }
            else
            {
                return BXLLIB_x86.PrintImageLibW(nHorizontalStartPos, nVerticalStartPos, pBitmapFilename, nDither, bDataCompression);
            }
        }

        public static bool SetShowMsgBox(bool bShow)
        {
            if (Is64Bit())
            {
                return BXLLIB_x64.SetShowMsgBox(bShow);
            }
            else
            {
                return BXLLIB_x86.SetShowMsgBox(bShow);
            }
        }

        public static void DEBUGLOG_ON()
        {
            if (Is64Bit())
            {
                BXLLIB_x64.DEBUGLOG_ON();
            }
            else
            {
                BXLLIB_x86.DEBUGLOG_ON();
            }
        }

        public static void DEBUGLOG_OFF()
        {
            if (Is64Bit())
            {
                BXLLIB_x64.DEBUGLOG_OFF();
            }
            else
            {
                BXLLIB_x86.DEBUGLOG_OFF();
            }
        }

        /////////////////////////////////////////////////////////////////
        //  Constant List

        //	Rotation
        public const int ROTATE_0 = 0;
        public const int ROTATE_90 = 1;
        public const int ROTATE_180 = 2;
        public const int ROTATE_270 = 3;

        //	Bar-code Type
        public const int CODE39 = 0;
        public const int CODE128 = 1;
        public const int I2OF5 = 2;
        public const int CODEBAR = 3;
        public const int CODE93 = 4;
        public const int UPC_A = 5;
        public const int UPC_E = 6;
        public const int EAN13 = 7;
        public const int EAN8 = 8;
        public const int UCC_EAN128 = 9;

        //	Device Fonts
        public const int ENG_9X15 = 0;	//	9 x 15
        public const int ENG_12X20 = 1;	//	12 x 20
        public const int ENG_16X25 = 2;	//	16 x 25
        public const int ENG_19X30 = 3;	//	19 x 30
        public const int ENG_24X38 = 4;	//	24 x 38
        public const int ENG_32X50 = 5;	//	32 x 50
        public const int ENG_48X76 = 6;	//	48 x 76
        public const int ENG_22X34 = 7;    //  22 x 34
        public const int ENG_28X44 = 8;    //  28 x 44
        public const int ENG_37X58 = 9;    //  37 x 58

        public const int KOR_16X16 = 0x61;	//	16 x 16
        public const int KOR_24X24 = 0x62;	//	24 x 24	
        public const int KOR_20X20 = 0x63; //  20 x 20
        public const int KOR_26X26 = 0x64; //  26 x 26
        public const int KOR_20X26 = 0x65; //  20 x 26
        public const int KOR_38X38 = 0x66;  // 36 x 36

        public const int CHN_GB2312 = 0x6D;
        public const int CHN_BIG5 = 0x6E;

        //	Speed
        public const int SPEED_25 = 0;
        public const int SPEED_30 = 1;
        public const int SPEED_40 = 2;
        public const int SPEED_50 = 3;
        public const int SPEED_60 = 4;
        public const int SPEED_70 = 5;

        //	Orientation
        public const int TOP = 0;
        public const int BOTTOM = 1;

        //	Media Type
        public const int GAP = 0;
        public const int CONTINUOUS = 1;
        public const int BLACKMARK = 2;

        //	Block Option
        public const int LINE_OVER_WRITING = 0;
        public const int LINE_EXCLUSIVE_OR = 1;
        public const int LINE_DELETE = 2;
        public const int SLOPE = 3;
        public const int BOX = 4;

        // Font Selection
        public const string ASCII = "U";
        public const string KS5601 = "K";
        public const string BIG5 = "B";
        public const string GB2312 = "G";
        public const string ShiftJIS = "J";


        // Font Alignment
        public const string LEFTALIGN = "L";
        public const string RIGHTALIGN = "R";
        public const string CENTERALIGN = "C";

        // Font Direction
        public const int LEFTTORIGHT = 0;
        public const int RIGHTTOLEFT = 1;

        // QRCode MODEL
        public const int QRMODEL_1 = 1;
        public const int QRMODEL_2 = 2;

        // QRCode ECC Level
        public const int QRECCLEVEL_L = 1;   // 7%
        public const int QRECCLEVEL_M = 2;   // 15%
        public const int QRECCLEVEL_Q = 3;   // 25%
        public const int QRECCLEVEL_H = 4;   // 30%

        // QRCode size
        public const int QRSIZE_1 = 1;
        public const int QRSIZE_2 = 2;
        public const int QRSIZE_3 = 3;
        public const int QRSIZE_4 = 4;
        public const int QRSIZE_5 = 5;
        public const int QRSIZE_6 = 6;
        public const int QRSIZE_7 = 7;
        public const int QRSIZE_8 = 8;
        public const int QRSIZE_9 = 9;

        // Dither option 
        public const int DITHER_NONE = -1;
        public const int DITHER_1 = 0;
        public const int DITHER_2 = 1;
        public const int DITHER_3 = 6;
        public const int DITHER_4 = 7;

        //	Alignment
        public const int ALIGN_LEFT = 0;
        public const int ALIGN_CENTER = 1;
        public const int ALIGN_RIGHT = 2;
        public const int ALIGN_BOTH_SIDE = 3;
    }
}
