diff --git a/App/Functions/Editor/ViewerControl.cs b/App/Functions/Editor/ViewerControl.cs index 728bfa7..f91bd23 100644 --- a/App/Functions/Editor/ViewerControl.cs +++ b/App/Functions/Editor/ViewerControl.cs @@ -4,11 +4,13 @@ using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Windows.Forms; +using CLR; using Cyotek.Windows.Forms; using Cyotek.Windows.Forms.Demo; using MuPDF; using MuPDF.Extensions; using PDFPatcher.Common; +using PDFPatcher.Functions.Editor; using DrawingPoint = System.Drawing.Point; using DrawingRectangle = System.Drawing.Rectangle; @@ -49,7 +51,7 @@ namespace PDFPatcher.Functions ZoomMode _zoomMode; float _zoomFactor; - Editor.ContentDirection _contentFlow; + ContentDirection _contentFlow; /// /// 页面的尺寸信息。 /// @@ -715,7 +717,7 @@ namespace PDFPatcher.Functions return ti; } foreach (var block in page.TextPage) { - if (block.IsImageBlock || block.Bound.Contains(point) == false) { + if (block.Type == BlockType.Image || block.Bound.Contains(point) == false) { continue; } HashSet s = null; @@ -778,7 +780,7 @@ namespace PDFPatcher.Functions return null; } foreach (var block in page.TextPage) { - if (block.IsImageBlock || pr.Intersect(block.Bound).IsEmpty) { + if (block.Type == BlockType.Image || pr.Intersect(block.Bound).IsEmpty) { continue; } var s = new HashSet(); @@ -1177,16 +1179,10 @@ namespace PDFPatcher.Functions void LoadPageBounds() { float w = 0, h = 0; for (int i = _mupdf.PageCount; i > 0; i--) { - using (var p = _mupdf.LoadPage(i - 1)) { - var b = p.Bound; - _pageBounds[i] = b; - if (b.Width > w) { - w = b.Width; - } - if (b.Height > h) { - h = b.Height; - } - } + var b = _mupdf.BoundPage(i - 1); + _pageBounds[i] = b; + b.Width.SetMax(ref w); + b.Height.SetMax(ref h); } _maxDimension = new SizeF(w, h); } diff --git a/App/Lib/CLR.dll b/App/Lib/CLR.dll new file mode 100644 index 0000000..480414e Binary files /dev/null and b/App/Lib/CLR.dll differ diff --git a/App/Lib/MuPDFLib.dll b/App/Lib/MuPDFLib.dll index 548f481..ed95181 100644 Binary files a/App/Lib/MuPDFLib.dll and b/App/Lib/MuPDFLib.dll differ diff --git a/App/PDFPatcher.csproj b/App/PDFPatcher.csproj index 92eab2b..c13a1af 100644 --- a/App/PDFPatcher.csproj +++ b/App/PDFPatcher.csproj @@ -50,6 +50,9 @@ Common\app.manifest + + Lib\CLR.dll + Lib\ColorPicker.dll diff --git a/App/Processor/Mupdf/MuPDFExtensions.cs b/App/Processor/Mupdf/MuPDFExtensions.cs index cb7549f..d9230d9 100644 --- a/App/Processor/Mupdf/MuPDFExtensions.cs +++ b/App/Processor/Mupdf/MuPDFExtensions.cs @@ -68,7 +68,7 @@ namespace MuPDF.Extensions var ctm = CalculateMatrix(page, width, height, options); var bbox = width > 0 && height > 0 ? new BBox(0, 0, width, height) : b.Transform(ctm).Round(); - var pix = Context.Instance.CreatePixmap(options.ColorSpace == ColorspaceKind.None ? ColorspaceKind.Rgb : options.ColorSpace, bbox); + var pix = Pixmap.Create(options.ColorSpace == ColorspaceKind.None ? ColorspaceKind.Rgb : options.ColorSpace, bbox); if (pix == null) { throw new MuException($"无法渲染页面:{(page.PageNumber + 1).ToText()}"); } diff --git a/App/Processor/Mupdf/PageLabelCollection.cs b/App/Processor/Mupdf/PageLabelCollection.cs index c572239..bed2af2 100644 --- a/App/Processor/Mupdf/PageLabelCollection.cs +++ b/App/Processor/Mupdf/PageLabelCollection.cs @@ -16,19 +16,23 @@ namespace MuPDF var pl = new List(); var l = document.Trailer.Locate(PdfNames.Root, PdfNames.PageLabels, PdfNames.Nums); if (l.IsArray) { - var a = l as PdfArray; - for (int i = 0; i < a.Count; i++) { - var n = a[i].IntegerValue; - var d = a[++i].UnderlyingObject as PdfDictionary; - var sp = d[PdfNames.St].IntegerValue; - var p = d[PdfNames.P] as PdfString; - pl.Add(new PageLabel(n, sp, p?.Value, d[PdfNames.S] is PdfName s ? (PageLabelStyle)(byte)s.Name[0] : PageLabelStyle.Default)); - } + ToPageLabels(pl, l); pl.Sort(); } _labels = pl; } + static void ToPageLabels(List pl, PdfObject l) { + var a = l as PdfArray; + for (int i = 0; i < a.Count; i++) { + var n = a[i].IntegerValue; + var d = a[++i].UnderlyingObject as PdfDictionary; + var sp = d[PdfNames.St].IntegerValue; + var p = d[PdfNames.P] as PdfString; + pl.Add(new PageLabel(n, sp, p?.Value, d[PdfNames.S] is PdfName s ? (PageLabelStyle)(byte)s.Name[0] : PageLabelStyle.None)); + } + } + /// /// 添加页码标签。如集合中存在相同页码的页码标签,则先将旧的标签删除,再添加新的页码标签。 /// @@ -119,13 +123,13 @@ namespace MuPDF } [DebuggerDisplay("From: {FromPageNumber}, Format: {Format (1)}")] - public readonly struct PageLabel : IComparable + public readonly struct PageLabel : IComparable, IEquatable { public readonly string Prefix; public readonly PageLabelStyle NumericStyle; public readonly int StartAt; public readonly int FromPageNumber; - public static PageLabel Empty = new PageLabel(-1, -1, null, PageLabelStyle.Default); + public static PageLabel Empty = new PageLabel(-1, -1, null, PageLabelStyle.None); public bool IsEmpty => FromPageNumber < 0; public PageLabel(int pageNumber, int startAt, string prefix, PageLabelStyle numericStyle) { @@ -142,32 +146,45 @@ namespace MuPDF public string Format(int pageNumber) { var n = pageNumber - FromPageNumber + (StartAt < 1 ? 0 : StartAt - 1); switch (NumericStyle) { - case PageLabelStyle.Default: + case PageLabelStyle.None: return Prefix; - case PageLabelStyle.Digit: + case PageLabelStyle.Decimal: return String.Concat(Prefix, n.ToText()); case PageLabelStyle.UpperRoman: return String.Concat(Prefix, n.ToRoman()); case PageLabelStyle.LowerRoman: return String.Concat(Prefix, n.ToRoman()).ToLowerInvariant(); - case PageLabelStyle.UpperAlphabetic: + case PageLabelStyle.UpperAlpha: return String.Concat(Prefix, n.ToAlphabet(true)); - case PageLabelStyle.LowerAlphabetic: + case PageLabelStyle.LowerAlpha: return String.Concat(Prefix, n.ToAlphabet(false)); default: - goto case PageLabelStyle.Digit; + goto case PageLabelStyle.Decimal; } } - } - public enum PageLabelStyle : byte - { - Default = (byte)'-', - DigitN = (byte)'D', - Digit = (byte)'d', - UpperRoman = (byte)'R', - LowerRoman = (byte)'r', - UpperAlphabetic = (byte)'A', - LowerAlphabetic = (byte)'a' + public bool Equals(PageLabel other) { + return FromPageNumber == other.FromPageNumber + && StartAt == other.StartAt + && Prefix == other.Prefix + && NumericStyle == other.NumericStyle; + } + + public override int GetHashCode() { + var hashCode = 1096239419; + hashCode = hashCode * -1521134295 + Prefix.GetHashCode(); + hashCode = hashCode * -1521134295 + (int)NumericStyle; + hashCode = hashCode * -1521134295 + StartAt; + hashCode = hashCode * -1521134295 + FromPageNumber; + return hashCode; + } + + public override bool Equals(object obj) { + return obj is PageLabel l && Equals(l); + } + + public static bool operator ==(PageLabel x, PageLabel y) { return x.Equals(y); } + + public static bool operator !=(PageLabel x, PageLabel y) { return !x.Equals(y); } } } diff --git a/App/Processor/PdfHelper.cs b/App/Processor/PdfHelper.cs index 692ddd8..fa63559 100644 --- a/App/Processor/PdfHelper.cs +++ b/App/Processor/PdfHelper.cs @@ -106,7 +106,7 @@ namespace PDFPatcher.Processor } internal static MuPDF.Document OpenMuDocument(string sourceFile) { - var d = MuPDF.Context.Instance.OpenDocument(sourceFile); + var d = MuPDF.Document.Open(sourceFile); if (d.NeedsPassword) { var authenticated = false; if (__PdfPasswordCache.TryGetValue(sourceFile, out byte[] password)) { diff --git a/App/Properties/AssemblyInfo.cs b/App/Properties/AssemblyInfo.cs index bc7871a..70f17aa 100644 --- a/App/Properties/AssemblyInfo.cs +++ b/App/Properties/AssemblyInfo.cs @@ -23,4 +23,4 @@ using System.Runtime.InteropServices; [assembly: Guid("e8969c5f-a5fe-4dce-a08b-555686483732")] [assembly: AssemblyVersion("1.1.0.0")] -[assembly: AssemblyFileVersion("1.1.0.4620")] +[assembly: AssemblyFileVersion("1.1.0.4657")]