mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
Compare commits
4 Commits
d69e3fa6a9
...
7e370a0eab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e370a0eab | ||
|
|
b9aa53166d | ||
|
|
0a2b1e076f | ||
|
|
f732718852 |
40
.github/workflows/prepare_release_pr.yml
vendored
Normal file
40
.github/workflows/prepare_release_pr.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
name: Create Release PR
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
bump_version:
|
||||||
|
runs-on: windows-2022
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Calculate next version
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
$newVer = .\tools\get-next-main-version.ps1
|
||||||
|
echo "NEW_VERSION=$newVer" >> $env:GITHUB_ENV
|
||||||
|
.\tools\set-version.ps1 $newVer -UpdateAssemblyAndFileVersion
|
||||||
|
|
||||||
|
git config user.name "github-actions"
|
||||||
|
git config user.email "github-actions@github.com"
|
||||||
|
|
||||||
|
git checkout -b release/$newVer
|
||||||
|
git commit -am "Release $newVer"
|
||||||
|
|
||||||
|
- name: Create Pull Request
|
||||||
|
uses: peter-evans/create-pull-request@v6
|
||||||
|
with:
|
||||||
|
branch: release/${{ env.NEW_VERSION }}
|
||||||
|
base: master
|
||||||
|
title: "Release ${{ env.NEW_VERSION }}"
|
||||||
|
body: "Automated release PR."
|
||||||
|
delete-branch: true
|
||||||
|
merge-method: rebase
|
||||||
53
.github/workflows/publish_nuget.yml
vendored
Normal file
53
.github/workflows/publish_nuget.yml
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
name: Publish
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_and_publish:
|
||||||
|
runs-on: windows-2022
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Verify tag points to master
|
||||||
|
id: verify
|
||||||
|
run: |
|
||||||
|
TAG_COMMIT=$(git rev-list -n 1 ${{ github.ref_name }})
|
||||||
|
if ! git branch -r --contains $TAG_COMMIT | grep -q 'origin/master'; then
|
||||||
|
echo "Tag is not on master — skipping publish"
|
||||||
|
exit 78 # 78 = neutral in GitHub Actions
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Set up .NET
|
||||||
|
uses: actions/setup-dotnet@v4
|
||||||
|
with:
|
||||||
|
dotnet-version: |
|
||||||
|
2.1.x
|
||||||
|
6.0.x
|
||||||
|
8.0.x
|
||||||
|
9.0.x
|
||||||
|
|
||||||
|
- name: Add msbuild to PATH
|
||||||
|
uses: microsoft/setup-msbuild@v2
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: dotnet test -c Release src/UglyToad.PdfPig.sln
|
||||||
|
|
||||||
|
- name: Build package
|
||||||
|
run: dotnet pack -c Release -o package tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg
|
||||||
|
|
||||||
|
- name: Publish to NuGet
|
||||||
|
run: dotnet nuget push package/*.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
|
||||||
|
|
||||||
|
- name: Create GitHub Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
tag_name: ${{ github.ref_name }}
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
53
.github/workflows/publish_release.yml
vendored
53
.github/workflows/publish_release.yml
vendored
@@ -1,53 +0,0 @@
|
|||||||
name: Release Publish
|
|
||||||
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
packages: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build_and_publish_release:
|
|
||||||
runs-on: windows-2022
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set up dotnet core
|
|
||||||
uses: actions/setup-dotnet@v4
|
|
||||||
with:
|
|
||||||
dotnet-version: |
|
|
||||||
2.1.x
|
|
||||||
6.0.x
|
|
||||||
8.0.x
|
|
||||||
9.0.x
|
|
||||||
|
|
||||||
- name: Add msbuild to PATH
|
|
||||||
uses: microsoft/setup-msbuild@v2
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: dotnet test -c Release src/UglyToad.PdfPig.sln
|
|
||||||
|
|
||||||
- name: Build package
|
|
||||||
run: dotnet pack -c Release -o package tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg
|
|
||||||
|
|
||||||
- name: Publish to NuGet
|
|
||||||
run: dotnet nuget push **/*.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
|
|
||||||
|
|
||||||
- name: Increment version after release
|
|
||||||
run: |
|
|
||||||
$newVer = .\tools\get-next-main-version.ps1
|
|
||||||
.\tools\set-version.ps1 $newVer -UpdateAssemblyAndFileVersion
|
|
||||||
git config user.name "github-actions"
|
|
||||||
git config user.email "github-actions@github.com"
|
|
||||||
|
|
||||||
git fetch origin master
|
|
||||||
git checkout master
|
|
||||||
git pull
|
|
||||||
|
|
||||||
git commit -am "Increment version to $newVer"
|
|
||||||
git push
|
|
||||||
43
.github/workflows/tag_release.yml
vendored
Normal file
43
.github/workflows/tag_release.yml
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
name: Tag Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tag_if_version_changed:
|
||||||
|
if: startsWith(github.event.head_commit.message, 'Release ')
|
||||||
|
runs-on: windows-2022
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Detect version change
|
||||||
|
id: versioncheck
|
||||||
|
run: |
|
||||||
|
git fetch origin master --depth=2
|
||||||
|
|
||||||
|
$diff = git diff HEAD^ HEAD -- tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj
|
||||||
|
|
||||||
|
if ($diff -match "<Version>") {
|
||||||
|
$version = (Select-String -Path tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj -Pattern "<Version>(.*)</Version>").Matches.Groups[1].Value
|
||||||
|
echo "version=$version" >> $env:GITHUB_OUTPUT
|
||||||
|
echo "create=true" >> $env:GITHUB_OUTPUT
|
||||||
|
} else {
|
||||||
|
echo "create=false" >> $env:GITHUB_OUTPUT
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Create tag
|
||||||
|
if: steps.versioncheck.outputs.create == 'true'
|
||||||
|
run: |
|
||||||
|
git config user.name "github-actions"
|
||||||
|
git config user.email "github-actions@github.com"
|
||||||
|
|
||||||
|
git tag "v${{ steps.versioncheck.outputs.version }}"
|
||||||
|
git push origin "v${{ steps.versioncheck.outputs.version }}"
|
||||||
Binary file not shown.
@@ -11,6 +11,31 @@
|
|||||||
|
|
||||||
public class GithubIssuesTests
|
public class GithubIssuesTests
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Issues1250()
|
||||||
|
{
|
||||||
|
// Issue comes from HasFormXObjectCircularReference
|
||||||
|
var path = IntegrationHelpers.GetDocumentPath("SPE8EF26T0545.pdf");
|
||||||
|
using (var document = PdfDocument.Open(path, new ParsingOptions() { UseLenientParsing = true }))
|
||||||
|
{
|
||||||
|
var page = document.GetPage(1);
|
||||||
|
Assert.NotNull(page);
|
||||||
|
Assert.NotEmpty(page.Letters);
|
||||||
|
|
||||||
|
page = document.GetPage(7);
|
||||||
|
Assert.NotNull(page);
|
||||||
|
Assert.NotEmpty(page.Letters);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure still no StackOverflowException
|
||||||
|
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("issue_671")))
|
||||||
|
{
|
||||||
|
var page = document.GetPage(1);
|
||||||
|
Assert.NotNull(page);
|
||||||
|
Assert.NotEmpty(page.Letters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Issues1248()
|
public void Issues1248()
|
||||||
{
|
{
|
||||||
@@ -29,7 +54,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Issues1238()
|
public void Issues1238()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -215,6 +215,8 @@
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void ShowText(IInputBytes bytes)
|
public void ShowText(IInputBytes bytes)
|
||||||
{
|
{
|
||||||
|
TextSequence++;
|
||||||
|
|
||||||
var currentState = GetCurrentState();
|
var currentState = GetCurrentState();
|
||||||
|
|
||||||
var font = currentState.FontState.FromExtendedGraphicsState
|
var font = currentState.FontState.FromExtendedGraphicsState
|
||||||
@@ -585,7 +587,8 @@
|
|||||||
if (hasCircularReference)
|
if (hasCircularReference)
|
||||||
{
|
{
|
||||||
if (ParsingOptions.UseLenientParsing)
|
if (ParsingOptions.UseLenientParsing)
|
||||||
{
|
{
|
||||||
|
// TODO - We might be removing too much, good for the moment. See Issues1250() for examples
|
||||||
operations = operations.Where(o => o is not InvokeNamedXObject xo || xo.Name != xObjectName)
|
operations = operations.Where(o => o is not InvokeNamedXObject xo || xo.Name != xObjectName)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
ParsingOptions.Logger.Warn(
|
ParsingOptions.Logger.Warn(
|
||||||
@@ -616,14 +619,56 @@
|
|||||||
/// <param name="xObjectName">The form's name.</param>
|
/// <param name="xObjectName">The form's name.</param>
|
||||||
/// <param name="operations">The form operations parsed from original form stream.</param>
|
/// <param name="operations">The form operations parsed from original form stream.</param>
|
||||||
protected virtual bool HasFormXObjectCircularReference(StreamToken formStream,
|
protected virtual bool HasFormXObjectCircularReference(StreamToken formStream,
|
||||||
NameToken xObjectName,
|
NameToken? xObjectName,
|
||||||
IReadOnlyList<IGraphicsStateOperation> operations)
|
IReadOnlyList<IGraphicsStateOperation> operations)
|
||||||
{
|
{
|
||||||
return xObjectName != null
|
if (xObjectName is null)
|
||||||
&& operations.OfType<InvokeNamedXObject>()?.Any(o => o.Name == xObjectName) ==
|
{
|
||||||
true // operations contain another form with same name
|
return false;
|
||||||
&& ResourceStore.TryGetXObject(xObjectName, out var result)
|
}
|
||||||
&& result.Data.Span.SequenceEqual(formStream.Data.Span); // The form contained in the operations has identical data to current form
|
|
||||||
|
if (operations.OfType<InvokeNamedXObject>()?.Any(o => o.Name == xObjectName) != true)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryGetXObjectToken(formStream, xObjectName, PdfScanner, out var t1))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ResourceStore.TryGetXObject(xObjectName, out var resourceStream))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryGetXObjectToken(resourceStream, xObjectName, PdfScanner, out var t2))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t1 is null || t2 is null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return t1.Equals(t2);
|
||||||
|
|
||||||
|
static bool TryGetXObjectToken(StreamToken streamToken, NameToken xObjectName, IPdfTokenScanner scanner, out IToken? token)
|
||||||
|
{
|
||||||
|
token = null;
|
||||||
|
if (!streamToken.StreamDictionary.TryGet<DictionaryToken>(NameToken.Resources, scanner, out var formResources))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!formResources.TryGet<DictionaryToken>(NameToken.Xobject, out var xObjectBase) || !xObjectBase.TryGet(xObjectName, out token))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return token is not null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
operationContext.ShowText(input);
|
operationContext.ShowText(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
string? EscapeText(string? text)
|
private static string? EscapeText(string? text)
|
||||||
{
|
{
|
||||||
if (text is null) return null;
|
if (text is null) return null;
|
||||||
// Fix Issue 350 from PDF Spec 1.7 (page 408) on handling 'special characters' of '(', ')' and '\'.
|
// Fix Issue 350 from PDF Spec 1.7 (page 408) on handling 'special characters' of '(', ')' and '\'.
|
||||||
|
|||||||
Reference in New Issue
Block a user