mirror of
https://github.com/wmjordan/PDFPatcher.git
synced 2026-10-19 06:21:06 +08:00
a25ebdfd4d
一般是在 if 控制范围很大的情况下进行调整,如果控制范围小则不调整。 从第三方代码的 Demo 中复制的代码块不修改。
96 lines
2.1 KiB
C#
96 lines
2.1 KiB
C#
|
|
namespace PDFPatcher.Processor
|
|
{
|
|
sealed class ClearDestinationOffsetProcessor : IPdfInfoXmlProcessor, IPdfInfoXmlProcessor<ClearDestinationOffsetProcessor.PositionType>
|
|
{
|
|
public enum PositionType { X, Y, XY }
|
|
|
|
PositionType _type;
|
|
public PositionType Parameter {
|
|
get => _type;
|
|
set {
|
|
_type = value;
|
|
switch (_type) {
|
|
case PositionType.X:
|
|
_name = "横";
|
|
break;
|
|
case PositionType.Y:
|
|
_name = "纵";
|
|
break;
|
|
default:
|
|
_name = string.Empty;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
string _name;
|
|
|
|
public ClearDestinationOffsetProcessor() {
|
|
}
|
|
public ClearDestinationOffsetProcessor(PositionType type) {
|
|
Parameter = type;
|
|
switch (type) {
|
|
case PositionType.X:
|
|
_name = "横";
|
|
break;
|
|
case PositionType.Y:
|
|
_name = "纵";
|
|
break;
|
|
default:
|
|
_name = string.Empty;
|
|
break;
|
|
}
|
|
}
|
|
#region IInfoDocProcessor 成员
|
|
|
|
public string Name => "清除" + _name + "坐标定位偏移值";
|
|
|
|
public IUndoAction Process(System.Xml.XmlElement item) {
|
|
if (item.GetAttribute(Constants.DestinationAttributes.View) == Constants.DestinationAttributes.ViewType.FitR) {
|
|
return null;
|
|
}
|
|
switch (_type) {
|
|
case PositionType.X:
|
|
return ClearPositionOffset(item, Constants.Coordinates.Left);
|
|
case PositionType.Y:
|
|
return ClearPositionOffset(item, Constants.Coordinates.Top);
|
|
case PositionType.XY:
|
|
var x = ClearPositionOffset(item, Constants.Coordinates.Left);
|
|
var y = ClearPositionOffset(item, Constants.Coordinates.Top);
|
|
if (x != null && y != null) {
|
|
var g = new UndoActionGroup();
|
|
g.Add(x);
|
|
g.Add(y);
|
|
return g;
|
|
}
|
|
else if (x != null) {
|
|
return x;
|
|
}
|
|
else if (y != null) {
|
|
return y;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static IUndoAction ClearPositionOffset(System.Xml.XmlElement item, string coordinate) {
|
|
if (!item.HasAttribute(coordinate)) {
|
|
return null;
|
|
}
|
|
|
|
var l = item.GetAttribute(coordinate);
|
|
if (l.Trim() == "0") {
|
|
return null;
|
|
}
|
|
item.RemoveAttribute(coordinate);
|
|
return new SetAttributeAction(item, coordinate, l);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|