public static void Write(Sequence seq, string path) { if (string.IsNullOrEmpty(path)) { throw new InvalidOperationException(); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string sequenceFilename = Path.Combine(path, "Quill.json"); string paintDataFilename = Path.Combine(path, "Quill.qbin"); string stateFilename = Path.Combine(path, "State.json"); // Write the qbin file first to update the data offsets. using (FileStream qbinStream = File.Create(paintDataFilename)) { QBinWriter qbinWriter = new QBinWriter(qbinStream); WriteLastStrokeId(seq, qbinWriter); WriteDrawingData(seq.RootLayer, qbinWriter); qbinWriter.Flush(); } WriteManifest(seq, sequenceFilename); WriteState(stateFilename); }
private static void WriteLastStrokeId(Sequence seq, QBinWriter qbinWriter) { // 8-byte header. // This value is sometimes seemingly broken in quill files. qbinWriter.Write(seq.LastStrokeId); int padding = 0; qbinWriter.Write(padding); }
/// <summary> /// Recursive function to write the paint data to file and update the layers offsets. /// This is called with the root layer and will write all the data for the sequence. /// </summary> private static void WriteDrawingData(Layer layer, QBinWriter qbinWriter) { if (layer.Type == LayerType.Group) { foreach (Layer l in ((LayerGroup)layer).Children) { if (l != null) { WriteDrawingData(l, qbinWriter); } } } else if (layer.Type == LayerType.Paint) { foreach (Drawing drawing in ((LayerPaint)layer).Drawings) { drawing.DataFileOffset = qbinWriter.BaseStream.Position; qbinWriter.Write(drawing.Data); } } }