mirror of
https://github.com/wmjordan/PDFPatcher.git
synced 2026-10-17 04:41:14 +08:00
!更新MuPDF库
This commit is contained in:
@@ -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;
|
||||
/// <summary>
|
||||
/// 页面的尺寸信息。
|
||||
/// </summary>
|
||||
@@ -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<TextFont> 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<int>();
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -50,6 +50,9 @@
|
||||
<ApplicationManifest>Common\app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="CLR">
|
||||
<HintPath>Lib\CLR.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ColorPicker">
|
||||
<HintPath>Lib\ColorPicker.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
@@ -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()}");
|
||||
}
|
||||
|
||||
@@ -16,19 +16,23 @@ namespace MuPDF
|
||||
var pl = new List<PageLabel>();
|
||||
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<PageLabel> 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));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加页码标签。如集合中存在相同页码的页码标签,则先将旧的标签删除,再添加新的页码标签。
|
||||
/// </summary>
|
||||
@@ -119,13 +123,13 @@ namespace MuPDF
|
||||
}
|
||||
|
||||
[DebuggerDisplay("From: {FromPageNumber}, Format: {Format (1)}")]
|
||||
public readonly struct PageLabel : IComparable<PageLabel>
|
||||
public readonly struct PageLabel : IComparable<PageLabel>, IEquatable<PageLabel>
|
||||
{
|
||||
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); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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")]
|
||||
|
||||
Reference in New Issue
Block a user