mirror of
https://github.com/wmjordan/PDFPatcher.git
synced 2026-10-17 04:41:14 +08:00
!更新MuPDFLib
This commit is contained in:
+740
-741
File diff suppressed because it is too large
Load Diff
@@ -6,110 +6,109 @@ using MuPDF;
|
||||
using PDFPatcher.Common;
|
||||
using MuRectangle = MuPDF.Box;
|
||||
|
||||
namespace PDFPatcher.Functions.Editor
|
||||
namespace PDFPatcher.Functions.Editor;
|
||||
|
||||
sealed partial class PagePropertyForm : DraggableForm
|
||||
{
|
||||
sealed partial class PagePropertyForm : DraggableForm
|
||||
byte[] _contentBytes;
|
||||
|
||||
public int PageNumber { get; set; }
|
||||
|
||||
public PagePropertyForm() {
|
||||
InitializeComponent();
|
||||
this.OnFirstLoad(OnLoad);
|
||||
}
|
||||
|
||||
void OnLoad() {
|
||||
MinimumSize = Size;
|
||||
_MainTab.SelectedIndexChanged += UpdateOpPage;
|
||||
_PageDimensionBox.SelectedIndexChanged += _PageDimensionBox_SelectedIndexChanged;
|
||||
_CloseButton.Click += (s, args) => Hide();
|
||||
_FontNameColumn.AsTyped<MuFontAndSize>(f => f.AspectGetter = o => o.FontName);
|
||||
_SizeColumn.AsTyped<MuFontAndSize>(f => f.AspectGetter = o => o.Size);
|
||||
_TextStyleBox.ScaleColumnWidths();
|
||||
}
|
||||
|
||||
void UpdateOpPage(object sender, EventArgs e) {
|
||||
if (_contentBytes != null && _MainTab.SelectedTab == _OpPage) {
|
||||
ContentStreamViewer.SetContent(_OpBox, _contentBytes);
|
||||
_contentBytes = null;
|
||||
_MainTab.SelectedIndexChanged -= UpdateOpPage;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadPage(Page page) {
|
||||
_PageDimensionBox.Items.Clear();
|
||||
AddBox(page, page.CropBox, Constants.Content.PageSettings.CropBox);
|
||||
AddBox(page, page.MediaBox, Constants.Content.PageSettings.MediaBox);
|
||||
AddBox(page, page.TrimBox, Constants.Content.PageSettings.TrimBox);
|
||||
AddBox(page, page.ArtBox, Constants.Content.PageSettings.ArtBox);
|
||||
AddBox(page, page.BleedBox, Constants.Content.PageSettings.BleedBox);
|
||||
_RotationBox.Text = page.Rotation.ToString();
|
||||
if (_PageDimensionBox.Items.Count > 0) {
|
||||
_PageDimensionBox.SelectedIndex = 0;
|
||||
}
|
||||
var ts = new HashSet<MuFontAndSize>(new FontAndSizeComparer());
|
||||
foreach (var block in page.TextPage) {
|
||||
foreach (var line in block) {
|
||||
var c = line.FirstCharacter;
|
||||
ts.Add(new MuFontAndSize(Model.PdfDocumentFont.RemoveSubsetPrefix(c.Font.Name), c.Size));
|
||||
}
|
||||
}
|
||||
_TextStyleBox.Objects = ts;
|
||||
_TextStyleBox.Sort(_SizeColumn, SortOrder.Descending);
|
||||
PageNumber = page.PageNumber + 1;
|
||||
_contentBytes = page.GetContentBytes();
|
||||
}
|
||||
|
||||
void AddBox(Page page, MuRectangle rect, string title) {
|
||||
if (rect.IsValid && !rect.IsEmpty) {
|
||||
_PageDimensionBox.Items.Add(new Box(rect, title));
|
||||
}
|
||||
}
|
||||
|
||||
void _PageDimensionBox_SelectedIndexChanged(object sender, EventArgs args) {
|
||||
if (_PageDimensionBox.SelectedItem is not Box v) {
|
||||
return;
|
||||
}
|
||||
var r = v.Rect;
|
||||
_TopBox.Text = r.Bottom.ToText();
|
||||
_RightBox.Text = r.Right.ToText();
|
||||
_BottomBox.Text = r.Top.ToText();
|
||||
_LeftBox.Text = r.Left.ToText();
|
||||
_WidthBox.Text = r.Width.ToText();
|
||||
_HeightBox.Text = r.Height.ToText();
|
||||
}
|
||||
|
||||
protected override void OnDeactivate(EventArgs e) {
|
||||
Hide();
|
||||
base.OnDeactivate(e);
|
||||
}
|
||||
|
||||
sealed class Box(MuRectangle rect, string title)
|
||||
{
|
||||
byte[] _contentBytes;
|
||||
public readonly MuRectangle Rect = rect;
|
||||
public readonly string Title = title;
|
||||
|
||||
public int PageNumber { get; set; }
|
||||
public override string ToString() {
|
||||
return Title;
|
||||
}
|
||||
}
|
||||
|
||||
public PagePropertyForm() {
|
||||
InitializeComponent();
|
||||
this.OnFirstLoad(OnLoad);
|
||||
sealed class MuFontAndSize(string fontName, float size)
|
||||
{
|
||||
public readonly string FontName = fontName;
|
||||
public readonly float Size = size;
|
||||
}
|
||||
|
||||
sealed class FontAndSizeComparer : IEqualityComparer<MuFontAndSize>
|
||||
{
|
||||
public bool Equals(MuFontAndSize x, MuFontAndSize y) {
|
||||
return x.FontName == y.FontName && x.Size == y.Size;
|
||||
}
|
||||
|
||||
void OnLoad() {
|
||||
MinimumSize = Size;
|
||||
_MainTab.SelectedIndexChanged += UpdateOpPage;
|
||||
_PageDimensionBox.SelectedIndexChanged += _PageDimensionBox_SelectedIndexChanged;
|
||||
_CloseButton.Click += (s, args) => Hide();
|
||||
_FontNameColumn.AsTyped<MuFontAndSize>(f => f.AspectGetter = o => o.FontName);
|
||||
_SizeColumn.AsTyped<MuFontAndSize>(f => f.AspectGetter = o => o.Size);
|
||||
_TextStyleBox.ScaleColumnWidths();
|
||||
}
|
||||
|
||||
void UpdateOpPage(object sender, EventArgs e) {
|
||||
if (_contentBytes != null && _MainTab.SelectedTab == _OpPage) {
|
||||
ContentStreamViewer.SetContent(_OpBox, _contentBytes);
|
||||
_contentBytes = null;
|
||||
_MainTab.SelectedIndexChanged -= UpdateOpPage;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadPage(Page page) {
|
||||
_PageDimensionBox.Items.Clear();
|
||||
AddBox(page, page.CropBox, Constants.Content.PageSettings.CropBox);
|
||||
AddBox(page, page.MediaBox, Constants.Content.PageSettings.MediaBox);
|
||||
AddBox(page, page.TrimBox, Constants.Content.PageSettings.TrimBox);
|
||||
AddBox(page, page.ArtBox, Constants.Content.PageSettings.ArtBox);
|
||||
AddBox(page, page.BleedBox, Constants.Content.PageSettings.BleedBox);
|
||||
_RotationBox.Text = page.Rotation.ToString();
|
||||
if (_PageDimensionBox.Items.Count > 0) {
|
||||
_PageDimensionBox.SelectedIndex = 0;
|
||||
}
|
||||
var ts = new HashSet<MuFontAndSize>(new FontAndSizeComparer());
|
||||
foreach (var block in page.Text) {
|
||||
foreach (var line in block) {
|
||||
var c = line.FirstCharacter;
|
||||
ts.Add(new MuFontAndSize(Model.PdfDocumentFont.RemoveSubsetPrefix(c.Font.Name), c.Size));
|
||||
}
|
||||
}
|
||||
_TextStyleBox.Objects = ts;
|
||||
_TextStyleBox.Sort(_SizeColumn, SortOrder.Descending);
|
||||
PageNumber = page.PageNumber + 1;
|
||||
_contentBytes = page.GetContentBytes();
|
||||
}
|
||||
|
||||
void AddBox(Page page, MuRectangle rect, string title) {
|
||||
if (rect.IsValid && !rect.IsEmpty) {
|
||||
_PageDimensionBox.Items.Add(new Box(rect, title));
|
||||
}
|
||||
}
|
||||
|
||||
void _PageDimensionBox_SelectedIndexChanged(object sender, EventArgs args) {
|
||||
if (_PageDimensionBox.SelectedItem is not Box v) {
|
||||
return;
|
||||
}
|
||||
var r = v.Rect;
|
||||
_TopBox.Text = r.Bottom.ToText();
|
||||
_RightBox.Text = r.Right.ToText();
|
||||
_BottomBox.Text = r.Top.ToText();
|
||||
_LeftBox.Text = r.Left.ToText();
|
||||
_WidthBox.Text = r.Width.ToText();
|
||||
_HeightBox.Text = r.Height.ToText();
|
||||
}
|
||||
|
||||
protected override void OnDeactivate(EventArgs e) {
|
||||
Hide();
|
||||
base.OnDeactivate(e);
|
||||
}
|
||||
|
||||
sealed class Box(MuRectangle rect, string title)
|
||||
{
|
||||
public readonly MuRectangle Rect = rect;
|
||||
public readonly string Title = title;
|
||||
|
||||
public override string ToString() {
|
||||
return Title;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class MuFontAndSize(string fontName, float size)
|
||||
{
|
||||
public readonly string FontName = fontName;
|
||||
public readonly float Size = size;
|
||||
}
|
||||
|
||||
sealed class FontAndSizeComparer : IEqualityComparer<MuFontAndSize>
|
||||
{
|
||||
public bool Equals(MuFontAndSize x, MuFontAndSize y) {
|
||||
return x.FontName == y.FontName && x.Size == y.Size;
|
||||
}
|
||||
|
||||
public int GetHashCode(MuFontAndSize obj) {
|
||||
return obj.FontName.GetHashCode() ^ obj.Size.GetHashCode();
|
||||
}
|
||||
public int GetHashCode(MuFontAndSize obj) {
|
||||
return obj.FontName.GetHashCode() ^ obj.Size.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,11 +744,11 @@ internal sealed class ViewerControl : ImageBoxEx
|
||||
var page = _cache.LoadPage(position.Page);
|
||||
var point = position.ToPageCoordinate(page);
|
||||
if (!page.Bound.Contains(point)
|
||||
|| !page.Text.Bound.Contains(point)) {
|
||||
|| !page.TextPage.Bound.Contains(point)) {
|
||||
return ti;
|
||||
}
|
||||
|
||||
foreach (var block in page.Text) {
|
||||
foreach (var block in page.TextPage) {
|
||||
if (block.Type == BlockType.Image || !block.Bound.Contains(point)) {
|
||||
continue;
|
||||
}
|
||||
@@ -810,10 +810,10 @@ internal sealed class ViewerControl : ImageBoxEx
|
||||
List<TextLine> r = null;
|
||||
var page = _cache.LoadPage(region.Page);
|
||||
var pr = region.ToPageCoordinate(page);
|
||||
if (pr.Intersect(page.Text.Bound).IsEmpty) {
|
||||
if (pr.Intersect(page.TextPage.Bound).IsEmpty) {
|
||||
return null;
|
||||
}
|
||||
foreach (var block in page.Text) {
|
||||
foreach (var block in page.TextPage) {
|
||||
if (block.Type == BlockType.Image || pr.Intersect(block.Bound).IsEmpty) {
|
||||
continue;
|
||||
}
|
||||
@@ -896,7 +896,7 @@ internal sealed class ViewerControl : ImageBoxEx
|
||||
Tracker.DebugMessage("render page " + pageNumber);
|
||||
bmp = p.RenderBitmapPage(width, height, _renderOptions, _cookie);
|
||||
_cache.SetBitmap(pageNumber, bmp);
|
||||
_cache.SetTextPage(pageNumber, p.Text);
|
||||
_cache.SetTextPage(pageNumber, p.TextPage);
|
||||
}
|
||||
}
|
||||
return bmp;
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user