protected void DataLoadLiteStream(Stream stream, HCLoadProc proc) { string vFileFormat = ""; ushort vFileVersion = 0; byte vLang = 0; HC._LoadFileFormatAndVersion(stream, ref vFileFormat, ref vFileVersion, ref vLang); using (HCStyle vStyle = new HCStyle()) { vStyle.LoadFromStream(stream, vFileVersion); proc(vFileVersion, vStyle); } }
public void LoadItemFromStreamAlone(Stream aStream, ref HCCustomItem aItem) { string vFileExt = ""; ushort vFileVersion = 0; byte vLan = 0; aStream.Position = 0; HC._LoadFileFormatAndVersion(aStream, ref vFileExt, ref vFileVersion, ref vLan); // 文件格式和版本 if ((vFileExt != HC.HC_EXT) && (vFileExt != "cff.")) { throw new Exception("加载失败,不是" + HC.HC_EXT + "文件!"); } HCStyle vStyle = new HCStyle(); vStyle.LoadFromStream(aStream, vFileVersion); int vStyleNo = HCStyle.Null; byte[] vBuffer = BitConverter.GetBytes(vStyleNo); aStream.Read(vBuffer, 0, vBuffer.Length); vStyleNo = BitConverter.ToInt32(vBuffer, 0); if (vStyleNo > HCStyle.Null) { HCTextStyle vTextStyle = vStyle.TextStyles[vStyleNo]; vStyleNo = Style.GetStyleNo(vTextStyle, true); } if (aItem == null) { aItem = CreateItemByStyle(vStyleNo); } aItem.LoadFromStream(aStream, vStyle, vFileVersion); aItem.StyleNo = vStyleNo; int vParaNo = aItem.ParaNo; HCParaStyle vParaStyle = vStyle.ParaStyles[vParaNo]; vParaNo = Style.GetParaNo(vParaStyle, true); aItem.ParaNo = vParaNo; }
public void LoadFromStream(Stream aStream) { this.BeginUpdate(); try { // 清除撤销恢复数据 FUndoList.Clear(); FUndoList.SaveState(); try { FUndoList.Enable = false; FData.Clear(); FStyle.Initialize(); aStream.Position = 0; string vFileExt = ""; ushort viVersion = 0; byte vLang = 0; HC._LoadFileFormatAndVersion(aStream, ref vFileExt, ref viVersion, ref vLang); if (vFileExt != HC.HC_EXT) { throw new Exception("加载失败,不是" + HC.HC_EXT + "文件!"); } FStyle.LoadFromStream(aStream, viVersion); FData.LoadFromStream(aStream, FStyle, viVersion); DoMapChanged(); } finally { FUndoList.RestoreState(); } } finally { this.EndUpdate(); } }
private void DoLoadFromStream(Stream stream, HCStyle style, LoadSectionProcHandler loadSectionProc) { stream.Position = 0; string vFileExt = ""; ushort vFileVersion = 0; byte vLang = 0; HC._LoadFileFormatAndVersion(stream, ref vFileExt, ref vFileVersion, ref vLang); if (vFileExt != HC.HC_EXT) { throw new Exception("加载失败,不是" + HC.HC_EXT + "文件!"); } if (vFileVersion > HC.HC_FileVersionInt) { throw new Exception("加载失败,当前编辑器最高支持版本为" + HC.HC_FileVersionInt.ToString() + "的文件,无法打开版本为" + vFileVersion.ToString() + "的文件!"); } DoLoadStreamBefor(stream, vFileVersion); // 触发加载前事件 style.LoadFromStream(stream, vFileVersion); // 加载样式表 loadSectionProc(vFileVersion); // 加载节数量、节数据 DoLoadStreamAfter(stream, vFileVersion); }
protected void Paste() { IDataObject vIData = Clipboard.GetDataObject(); if (vIData.GetDataPresent(HC.HC_EXT)) { MemoryStream vStream = (MemoryStream)vIData.GetData(HC.HC_EXT); try { string vFileFormat = ""; ushort vFileVersion = 0; byte vLan = 0; vStream.Position = 0; HC._LoadFileFormatAndVersion(vStream, ref vFileFormat, ref vFileVersion, ref vLan); // 文件格式和版本 HCStyle vStyle = new HCStyle(); try { vStyle.LoadFromStream(vStream, vFileVersion); this.BeginUpdate(); try { FData.InsertStream(vStream, vStyle, vFileVersion); } finally { this.EndUpdate(); } } finally { vStyle.Dispose(); } } finally { vStream.Close(); vStream.Dispose(); } } else if (vIData.GetDataPresent(DataFormats.Text)) { FData.InsertText(Clipboard.GetText()); } else if (vIData.GetDataPresent(DataFormats.Bitmap)) { Image vImage = (Image)vIData.GetData(typeof(Bitmap)); HCRichData vTopData = FData.GetTopLevelData() as HCRichData; HCImageItem vImageItem = new HCImageItem(vTopData); vImageItem.Image = new Bitmap(vImage); vImageItem.Width = vImageItem.Image.Width; vImageItem.Height = vImageItem.Image.Height; vImageItem.RestrainSize(vTopData.Width, vImageItem.Height); FData.InsertItem(vImageItem); } }