From 9b6b13cbe3446a9170753e8e078745a01ee54cb9 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Mon, 6 Feb 2017 23:46:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OpenDocument/OdtTemplateTest.cs | 3 ++- Sandwych.Reporting/OpenDocument/OdfTemplate.cs | 18 ++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Sandwych.Reporting.Test/OpenDocument/OdtTemplateTest.cs b/Sandwych.Reporting.Test/OpenDocument/OdtTemplateTest.cs index 575e8fb..70aac42 100644 --- a/Sandwych.Reporting.Test/OpenDocument/OdtTemplateTest.cs +++ b/Sandwych.Reporting.Test/OpenDocument/OdtTemplateTest.cs @@ -114,8 +114,9 @@ public void TestStatements() [Test] public void UseImageShouldBeOk() { + var image1Path = TemplateTestHelper.GetTestResourceAbsolutleFilePath("resources/go-home.PNG"); var ctx = new Dictionary() { - { "image1", new Image("png", File.ReadAllBytes("resources/go-home.PNG")) }, + { "image1", new Image("png", File.ReadAllBytes(image1Path)) }, }; var result = OdfTemplateTestHelper.RenderTemplate( diff --git a/Sandwych.Reporting/OpenDocument/OdfTemplate.cs b/Sandwych.Reporting/OpenDocument/OdfTemplate.cs index 59ad780..82cdbd4 100644 --- a/Sandwych.Reporting/OpenDocument/OdfTemplate.cs +++ b/Sandwych.Reporting/OpenDocument/OdfTemplate.cs @@ -65,24 +65,20 @@ public override void Save(Stream outStream) throw new ArgumentNullException("outStream"); } - //ODF 格式约定 mimetype 必须为第一个文件 + //ODF 格式约定 mimetype 必须为 ZIP 包里的第一个文件 if (!this.entries.ContainsKey(MimeTypeEntryPath)) { throw new InvalidDataException("Entry 'mimetype' not found"); } - using (var ze = new ZipArchive(outStream, ZipArchiveMode.Create)) + using (var zip = new ZipArchive(outStream, ZipArchiveMode.Create)) { - this.AppendZipEntry(ze, MimeTypeEntryPath); + this.AppendZipEntry(zip, MimeTypeEntryPath); + this.entries.Remove(MimeTypeEntryPath); foreach (var item in this.entries) { - if (item.Key == MimeTypeEntryPath) - { - continue; - } - - this.AppendZipEntry(ze, item.Key); + this.AppendZipEntry(zip, item.Key); } } } @@ -102,11 +98,13 @@ private void AppendZipEntry(ZipArchive archive, string name) case "JPEG": case "JPG": case "PNG": + case "MP3": + case "MP4": cl = CompressionLevel.NoCompression; break; default: - cl = CompressionLevel.Optimal; + cl = CompressionLevel.Fastest; break; } var zae = archive.CreateEntry(name, cl);