コード例 #1
0
        /// <summary>
        /// 打印文本内容
        /// </summary>
        /// <param name="message">打印的内容</param>
        /// <param name="err">2:没有开启蓝牙,3:没有连接打印机,4:butmap为null,5:程序出现异常</param>
        /// <returns></returns>
        public bool SendMessage(Java.Lang.String message, out int err)
        {
            err = 0;
            if (!isopen)
            {
                err = 2;
                return(false);
            }
            if (this.chatService.GetState() != BluetoothService.STATE_CONNECTED)
            {
                err = 3;
                return(false);
            }

            if (message.Length() <= 0)
            {
                err = 4;
                return(false);
            }
            try
            {
                byte[] send = message.GetBytes();
                chatService.Write(send);
                return(true);
            }
            catch
            {
                err = 5;
                return(false);
            }

            // Get the message bytes and tell the BluetoothService to write
        }
コード例 #2
0
        /// <summary>
        /// 打印文本内容
        /// </summary>
        /// <param name="message">打印的内容</param>
        /// <param name="err">2:没有开启蓝牙,3:没有连接打印机,4:butmap为null,5:程序出现异常</param>
        /// <returns></returns>
        public int SendMessage(Java.Lang.String message)
        {
            int err = 0;

            if (!isopen)
            {
                err = (int)PrintError.OpenFailure;
                return(err);
            }
            if (this.chatService.GetState() != BluetoothService.STATE_CONNECTED)
            {
                err = (int)PrintError.ConnectedFailure;
                return(err);
            }

            if (message.Length() <= 0)
            {
                err = (int)PrintError.SendNull;;
                return(err);
            }
            try
            {
                byte[] send = message.GetBytes("GB2312");
                chatService.Write(send);
                err = 1;
                return(err);
            }
            catch
            {
                err = (int)PrintError.SendFailure;;
                return(err);
            }

            // Get the message bytes and tell the BluetoothService to write
        }
コード例 #3
0
        /**
         * 根据起始位置指针,读取一页内容
         *
         * @return
         */
        private Vector pageDown()
        {
            Java.Lang.String strParagraph = new Java.Lang.String();
            Vector           lines        = new Vector();
            int paraSpace = 0;

            mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
            while ((lines.Size() < mPageLineCount) && (curEndPos < mbBufferLen))
            {
                byte[] parabuffer = readParagraphForward(curEndPos);
                curEndPos += parabuffer.Length;
                try
                {
                    strParagraph = new Java.Lang.String(parabuffer, charset);
                }
                catch (UnsupportedEncodingException e)
                {
                    e.PrintStackTrace();
                }
                strParagraph = new Java.Lang.String(strParagraph.ReplaceAll("\r\n", "  "));
                strParagraph = new Java.Lang.String(strParagraph.ReplaceAll("\n", " ")); // 段落中的换行符去掉,绘制的时候再换行

                while (strParagraph.Length() > 0)
                {
                    int paintSize = mPaint.BreakText(strParagraph.ToString(), true, mVisibleWidth, null);
                    lines.Add(strParagraph.Substring(0, paintSize));
                    strParagraph = new Java.Lang.String(strParagraph.Substring(paintSize));
                    if (lines.Size() >= mPageLineCount)
                    {
                        break;
                    }
                }
                lines.Set(lines.Size() - 1, lines.Get(lines.Size() - 1) + "@");
                if (strParagraph.Length() != 0)
                {
                    try
                    {
                        curEndPos -= (strParagraph).GetBytes(charset).Length;
                    }
                    catch (UnsupportedEncodingException e)
                    {
                        e.PrintStackTrace();
                    }
                }
                paraSpace     += mLineSpace;
                mPageLineCount = (mVisibleHeight - paraSpace) / (mFontSize + mLineSpace);
            }
            return(lines);
        }
コード例 #4
0
        /**
         * 指针移到上一页页首
         */
        private void pageUp()
        {
            Java.Lang.String strParagraph = new Java.Lang.String();
            Vector           lines        = new Vector(); // 页面行
            int paraSpace = 0;

            mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
            while ((lines.Size() < mPageLineCount) && (curBeginPos > 0))
            {
                Vector paraLines  = new Vector();                   // 段落行
                byte[] parabuffer = readParagraphBack(curBeginPos); // 1.读取上一个段落

                curBeginPos -= parabuffer.Length;                   // 2.变换起始位置指针
                try
                {
                    strParagraph = new Java.Lang.String(parabuffer, charset);
                }
                catch (UnsupportedEncodingException e)
                {
                    e.PrintStackTrace();
                }
                strParagraph = new Java.Lang.String(strParagraph.ReplaceAll("\r\n", "  "));
                strParagraph = new Java.Lang.String(strParagraph.ReplaceAll("\n", " "));

                while (strParagraph.Length() > 0)
                { // 3.逐行添加到lines
                    int paintSize = mPaint.BreakText(strParagraph.ToString(), true, mVisibleWidth, null);
                    paraLines.Add(strParagraph.Substring(0, paintSize));
                    strParagraph = new Java.Lang.String(strParagraph.Substring(paintSize));
                }
                lines.AddAll(0, paraLines.ToArray());

                while (lines.Size() > mPageLineCount)
                { // 4.如果段落添加完,但是超出一页,则超出部分需删减
                    try
                    {
                        curBeginPos += (new Java.Lang.String(lines.Get(0).ToString())).GetBytes(charset).Length; // 5.删减行数同时起始位置指针也要跟着偏移
                        lines.Remove(0);
                    }
                    catch (UnsupportedEncodingException e)
                    {
                        e.PrintStackTrace();
                    }
                }
                curEndPos      = curBeginPos;                                             // 6.最后结束指针指向下一段的开始处
                paraSpace     += mLineSpace;
                mPageLineCount = (mVisibleHeight - paraSpace) / (mFontSize + mLineSpace); // 添加段落间距,实时更新容纳行数
            }
        }