private bool ReloadFile(ref CUIDocumentView view) { var info = view.Info; if (info.StreamPositon > info.DocumentOffset) { if (view.UnicodeStart << 1 < PRE_SIZE) { //要向前加载 throw new NotImplementedException(); } } else { if (view.UnicodeEnd > view.Info.UnicodeSize - (PRE_SIZE >> 1)) { //要向后加载 throw new NotImplementedException(); } } return(false);//不需要重新加载 }
private void Init() { if (IT8951API.Open() == 0) { MessageBox.Show("无法打开设备"); return; } UInt32[] deviceInfoData = new UInt32[28]; if (IT8951API.GetDeviceInfo(deviceInfoData) != deviceInfoData.Length) { MessageBox.Show("无法获取设备信息"); return; } DeviceInfo = new DeviceInfo(deviceInfoData); //CUIEnvironment.WidthOfPixel = (int)DeviceInfo.Width; CUIEnvironment.WidthOfPixel = (int)DeviceInfo.Width - 4; CUIEnvironment.HeightOfPixel = (int)DeviceInfo.Height; LblWidth.Text = CUIEnvironment.WidthOfPixel.ToString(); LblHeight.Text = CUIEnvironment.HeightOfPixel.ToString(); LblAddress.Text = DeviceInfo.ImageBufBase.ToString(); var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test.txt"); Contract.Ensures(File.Exists(path)); //应该做一次文档格式转换,比如,转为Unicode编码,文档的前128个字节固定空出来; //todo 加载时,应该往前一段距离加载,将起点落在10-90%之间 CDocumentInfo documentInfo = new CDocumentInfo(); //using (Stream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) //{ // Int32 buffSize = BUFF_SIZE; // Int32 unicodeSize = BUFF_SIZE >> 1; // documentInfo.FileSize = (Int32)stream.Length; // documentInfo.Buffer = (ushort*)Marshal.AllocHGlobal(buffSize); // documentInfo.BufferSize = unicodeSize; // documentInfo.Path = path; // documentInfo.StreamPositon = documentInfo.StreamPositon + buffSize; // documentInfo.IsEnd = documentInfo.StreamPositon < documentInfo.FileSize; //} LoadDocument(ref documentInfo, path, 0); //采用8bits格式 var image = new Bitmap(CUIEnvironment.WidthOfPixel, CUIEnvironment.HeightOfPixel, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); //配置调色板 ColorPalette palette = image.Palette;//这里取得的似乎是复制体 for (int i = 0; i < 256; i++) { palette.Entries[i] = Color.FromArgb(i, i, i); } image.Palette = palette; //for (int i = 0; i < byte.MaxValue; i++) //{ // var c = image.Palette.Entries[i]; // image.Palette.Entries[i] = Color.FromArgb(i, i, i); //} //刷成白色背景 var bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat); var temp = Enumerable.Repeat <byte>(byte.MaxValue, image.Width * image.Height).ToArray(); Marshal.Copy(temp, 0, bitmapData.Scan0, temp.Length); image.UnlockBits(bitmapData); Picture.Image = image; CUIFrameMethods.Create(out frame, CUIFrameType.Main); CPadding padding; CCommonLib.CCommonInits.InitPaddingAll(out padding, 12); var view = CUIViewMethods.Create(CUIViewType.Document); //view.FontSize = 12; CFontInfo fontInfo; CG.GetValidFontSize(view.Style.FontSize, out fontInfo); view.Size = new CSize() { Width = (int)(CUIEnvironment.WidthOfPixel - padding.Left - padding.Right), Height = (int)(CUIEnvironment.HeightOfPixel - padding.Top - padding.Bottom) }; view.Style.FontSize = fontInfo.FontSize; view.Style.FontColor = 0x00; view.Style.BackColor = 0xFF; view.Style.BorderColor = 0xFF000030; view.Style.BorderThickness = 0; //view.Text = (char*)documentInfo.Buffer; //view.TextSize = documentInfo.BufferSize; view.Location = new CPoint() { X = padding.Left, Y = padding.Top }; documentView = (CUIDocumentView)view.Properties; documentView.Info = documentInfo; documentView.Style = new CUIDocumentStyle() { MarginLeft = 0, MarginRight = 0, MarginTop = 0, MarginBottom = 0, SectionFirstLineMarginLeft = fontInfo.Width * 2, //LineMarginTop = fontInfo.Height >> 1, LineMarginTop = 2, LineMarginBottom = 0, RemainLines = 1, }; CUIFrameMethods.AddToFrame(ref frame, view); CUIApp.Add(in frame); Draw(); }