예제 #1
0
        public void AddInfo(string info)
        {
            CTextInfo textInfo = new CTextInfo();

            textInfo.Info = info;
            textInfo.Time = DateTime.Now;
            if (NewDBSystemInfo != null)
            {
                NewDBSystemInfo(this, new CEventSingleArgs <CTextInfo>(textInfo));
            }
        }
        unsafe void Draw()
        {
            CBitmap bitmap;

            CGraphic.CGraphicInits.InitBitmap(out bitmap, CPixelFormat.Format8bppIndexed, CUIEnvironment.WidthOfPixel, CUIEnvironment.HeightOfPixel);

            var rectangle = new CRect()
            {
                MinX = 10,
                MinY = 10,
                MaxX = 480,
                MaxY = 310
            };
            var modifyRect = rectangle;

            CG.DrawRectangle2(ref bitmap, 2, rectangle.MinX, rectangle.MinY, rectangle.MaxX, rectangle.MaxY, 0xF);


            CFontInfo fontInfo;

            CG.GetValidFontSize(CFont.DefaultSize, out fontInfo);
            var text = @"电子墨水屏采用“微胶囊电泳显示”技术进行图像显示,其工作原理是悬浮在液体中的带电纳米粒子受到电场作用而产生迁移, 在环境光下通过反射形成接近传统印刷纸张的显示效果。电子墨水屏能够在灯光,自然光等环境光下清晰地显示画面,无需背光,可视角度几乎达到180°。因其媲美传统纸张的显示效果, 常被用于阅读器之类的应用。";

            text = String.Intern(text);//放到常量
            CTextInfo textInfo = new CTextInfo()
            {
                Start = 0, End = text.Length, Length = text.Length
            };

            textInfo.Text = Utils.ToCharPointer(text);
            CRect renderRect;

            CG.DrawText(ref bitmap, textInfo, fontInfo, rectangle, new CPoint()
            {
                X = fontInfo.Width * 2, Y = 8
            }, out renderRect);

            var image = (Bitmap)Picture.Image;

            EInkRender.DrawToBitmap(ref image, bitmap, modifyRect);
        }
예제 #3
0
        private unsafe void BtnRender_Click(object sender, EventArgs e)
        {
            int fontSize = (int)NudFontSize.Value;

            CFont.Init(MakePath());
            Bitmap image = new Bitmap(Picture.Width, Picture.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            Picture.Image = image;
            Graphics g = Graphics.FromImage(image);

            g.Clear(Color.White);
            g.Dispose();
            var text = string.Intern(Txt.Text);//弄成常量
            //var text = Charset.Content;
            CFontInfo fontInfo;

            CG.GetValidFontSize((int)NudFontSize.Value, out fontInfo);
            CBitmap bitmap;

            CGraphicInits.InitBitmap(out bitmap, CPixelFormat.Format8bppIndexed, image.Width, image.Height);
            CTextInfo textInfo = new CTextInfo()
            {
                Start  = 0,
                End    = text.Length,
                Length = text.Length
            };

            textInfo.Text = Utils.ToCharPointer(text);
            var modifyRect = new CRect();
            var rect       = new CRect()
            {
                MinX = 0, MinY = 0, MaxX = 400, MaxY = 300
            };

            CG.DrawText(ref bitmap, textInfo, fontInfo, rect, new CPoint()
            {
                X = 0, Y = 0
            }, out modifyRect);
            EInkRender.DrawToBitmap(ref image, bitmap, rect);

            ////注意:设置负数的缩进,会有文本绘制不全的问题
            //FontMargin margin = new FontMargin();
            //margin.PageMarginLeft = 12;
            //margin.PageMarginRight = margin.PageMarginLeft;
            //margin.PageMarginTop = margin.PageMarginLeft;
            //margin.PageMarginRight = margin.PageMarginLeft;
            //margin.LineMarginTop = 4;
            //margin.LineMarginBottom = 2;
            //margin.MarginLeft = -2;
            //margin.MarginRight = -1;
            //margin.MarginTop = 0;
            //margin.MarginBottom = 0;
            //margin.ParagraphFirstLineMarginLeft = (short)((info.Width + margin.MarginLeft + margin.MarginRight) * 2);//空2个字符

            //int startX = margin.PageMarginLeft + margin.MarginLeft;
            //int x = startX + margin.ParagraphFirstLineMarginLeft;
            //int y = margin.PageMarginTop + margin.MarginTop;
            //FontBitmap matrix;
            //int maxX = bitmap.Width - margin.PageMarginRight - margin.MarginRight - 1;
            //int maxY = bitmap.Height - margin.PageMarginBottom - margin.LineMarginBottom - margin.MarginBottom - 1;
            //int lineHeight = info.Height + margin.LineMarginTop + margin.LineMarginBottom + margin.MarginTop + margin.MarginBottom;
            ////注意
            //for (int i = 0; i < text.Length; i++)
            //{
            //    var character = text[i];
            //    //强制换行
            //    if (character == '\n' || (character == '\r' && i < text.Length - 1) && character == '\n')
            //    {
            //        x = startX + margin.ParagraphFirstLineMarginLeft;
            //        y += lineHeight;
            //        //跳过\n
            //        if (character == '\r')
            //        {
            //            i++;
            //        }
            //        continue;
            //    }

            //    if (Fonts.ePageGetFontMatrix(character, fontSize, out matrix))
            //    {
            //        int width = info.Width;
            //        //新起一行
            //        if (x + width > maxX)
            //        {
            //            x = startX;
            //            y += lineHeight;
            //        }
            //        if (y > maxY)
            //        {
            //            break;
            //        }
            //        Fonts.ePageDrawFontMatrix(bitmap, x, y, matrix, info);

            //        x += width + margin.MarginLeft + margin.MarginRight;
            //    }
            //}
        }