Implemented handling of %%Include DSC comments in EpsImage, adjusted and added test cases

This commit is contained in:
vog 2011-07-13 01:51:20 +00:00
parent e0d3fabab1
commit 9389aaa89a
15 changed files with 409 additions and 17 deletions

View File

@ -451,7 +451,7 @@ namespace {
#endif
}
}
if (line == "%%EOF" || (line.size() >= 1 && line[0] != '%')) {
if (line == "%%EOF" || startsWith(line, "%%IncludeDocument:") || startsWith(line, "%%BeginDocument:") || (line.size() >= 1 && line[0] != '%')) {
if (posPage == posEndEps && posEndComments != posEndEps && !inDefaultsOrPrologOrSetup && !inRemovableEmbedding && !onlyWhitespaces(line)) {
posPage = startPos;
implicitPage = true;
@ -542,12 +542,6 @@ namespace {
} else if (line == "%%EOF") {
posEof = startPos;
} else if (startsWith(line, "%%BeginDocument:")) {
if (posEndPageSetup == posEndEps) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Nested document at invalid position (before explicit or implicit EndPageSetup): " << startPos << "\n";
#endif
throw Error(write ? 21 : 14);
}
// TODO: Add support for nested documents!
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Nested documents are currently not supported. Found nested document at position: " << startPos << "\n";
@ -564,12 +558,6 @@ namespace {
EXV_WARNING << "Unable to handle multiple PostScript pages. Found second page at position: " << startPos << "\n";
#endif
throw Error(write ? 21 : 14);
} else if (startsWith(line, "%%Include")) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Unable to handle PostScript %%Include DSC comments yet. Please provide your "
"sample EPS file to the Exiv2 project: http://dev.exiv2.org/projects/exiv2\n";
#endif
throw Error(write ? 21 : 14);
} else {
#ifdef DEBUG
significantLine = false;

View File

@ -0,0 +1,9 @@
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 5 105 105
%%DocumentNeededResources: font Symbol
%%IncludeResource: font Symbol
10 setlinewidth
10 10 moveto
0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath
stroke

View File

@ -0,0 +1,17 @@
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 5 105 105
%%DocumentNeededResources: font Symbol
%ADO_ContainsXMP: NoMain
%%Pages: 1
%Exiv2Version: _Exiv2Version_
%Exiv2Website: http://www.exiv2.org/
%%EndComments
%%IncludeResource: font Symbol
%%Page: 1 1
%%EndPageComments
10 setlinewidth
10 10 moveto
0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath
stroke
%%EOF

View File

@ -0,0 +1,73 @@
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 5 105 105
%%DocumentNeededResources: font Symbol
%%LanguageLevel: 2
%ADO_ContainsXMP: MainFirst
%%Pages: 1
%Exiv2Version: _Exiv2Version_
%Exiv2Website: http://www.exiv2.org/
%%EndComments
%%IncludeResource: font Symbol
%%Page: 1 1
%%EndPageComments
%%BeginPageSetup
%Exiv2BeginXMP: Before %%EndPageSetup
/currentdistillerparams where
{pop currentdistillerparams /CoreDistVersion get 5000 lt} {true} ifelse
{userdict /Exiv2_pdfmark /cleartomark load put
userdict /Exiv2_metafile_pdfmark {flushfile cleartomark} bind put}
{userdict /Exiv2_pdfmark /pdfmark load put
userdict /Exiv2_metafile_pdfmark {/PUT pdfmark} bind put} ifelse
[/NamespacePush Exiv2_pdfmark
[/_objdef {Exiv2_metadata_stream} /type /stream /OBJ Exiv2_pdfmark
[{Exiv2_metadata_stream} 2 dict begin
/Type /Metadata def /Subtype /XML def currentdict end /PUT Exiv2_pdfmark
[{Exiv2_metadata_stream}
currentfile 0 (% &&end XMP packet marker&&)
/SubFileDecode filter Exiv2_metafile_pdfmark
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:test="http://www.example.com/"
test:test="TEST"/>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
% &&end XMP packet marker&&
[/Document 1 dict begin
/Metadata {Exiv2_metadata_stream} def currentdict end /BDC Exiv2_pdfmark
%Exiv2EndXMP
%%EndPageSetup
10 setlinewidth
10 10 moveto
0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath
stroke
%%PageTrailer
%Exiv2BeginXMP: After %%PageTrailer
[/EMC Exiv2_pdfmark
[/NamespacePop Exiv2_pdfmark
%Exiv2EndXMP
%%EOF

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?>

View File

@ -0,0 +1,14 @@
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 5 105 105
%%BeginDocument: dummy_document.eps
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 25 25 85 85
20 setlinewidth
35 35 moveto
0 40 rlineto 40 0 rlineto 0 -40 rlineto closepath
stroke
%%EndDocument
10 setlinewidth
10 10 moveto
0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath
stroke

View File

@ -0,0 +1,16 @@
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 5 105 105
save
%%BeginDocument: dummy_document.eps
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 25 25 85 85
20 setlinewidth
35 35 moveto
0 40 rlineto 40 0 rlineto 0 -40 rlineto closepath
stroke
%%EndDocument
restore
10 setlinewidth
10 10 moveto
0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath
stroke

View File

@ -0,0 +1,9 @@
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 5 105 105
%%DocumentNeededResources: dummy_document.eps
%%EndComments
%%IncludeDocument: dummy_document.eps
10 setlinewidth
10 10 moveto
0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath
stroke

View File

@ -0,0 +1,16 @@
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 5 105 105
%%DocumentNeededResources: dummy_document.eps
%ADO_ContainsXMP: NoMain
%%Pages: 1
%Exiv2Version: _Exiv2Version_
%Exiv2Website: http://www.exiv2.org/
%%EndComments
%%Page: 1 1
%%EndPageComments
%%IncludeDocument: dummy_document.eps
10 setlinewidth
10 10 moveto
0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath
stroke
%%EOF

View File

@ -0,0 +1,72 @@
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 5 105 105
%%DocumentNeededResources: dummy_document.eps
%%LanguageLevel: 2
%ADO_ContainsXMP: MainFirst
%%Pages: 1
%Exiv2Version: _Exiv2Version_
%Exiv2Website: http://www.exiv2.org/
%%EndComments
%%Page: 1 1
%%EndPageComments
%%BeginPageSetup
%Exiv2BeginXMP: Before %%EndPageSetup
/currentdistillerparams where
{pop currentdistillerparams /CoreDistVersion get 5000 lt} {true} ifelse
{userdict /Exiv2_pdfmark /cleartomark load put
userdict /Exiv2_metafile_pdfmark {flushfile cleartomark} bind put}
{userdict /Exiv2_pdfmark /pdfmark load put
userdict /Exiv2_metafile_pdfmark {/PUT pdfmark} bind put} ifelse
[/NamespacePush Exiv2_pdfmark
[/_objdef {Exiv2_metadata_stream} /type /stream /OBJ Exiv2_pdfmark
[{Exiv2_metadata_stream} 2 dict begin
/Type /Metadata def /Subtype /XML def currentdict end /PUT Exiv2_pdfmark
[{Exiv2_metadata_stream}
currentfile 0 (% &&end XMP packet marker&&)
/SubFileDecode filter Exiv2_metafile_pdfmark
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:test="http://www.example.com/"
test:test="TEST"/>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
% &&end XMP packet marker&&
[/Document 1 dict begin
/Metadata {Exiv2_metadata_stream} def currentdict end /BDC Exiv2_pdfmark
%Exiv2EndXMP
%%EndPageSetup
%%IncludeDocument: dummy_document.eps
10 setlinewidth
10 10 moveto
0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath
stroke
%%PageTrailer
%Exiv2BeginXMP: After %%PageTrailer
[/EMC Exiv2_pdfmark
[/NamespacePop Exiv2_pdfmark
%Exiv2EndXMP
%%EOF

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?>

View File

@ -0,0 +1,18 @@
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 5 105 105
%%DocumentNeededResources: dummy_document.eps
%ADO_ContainsXMP: NoMain
%%Pages: 1
%Exiv2Version: _Exiv2Version_
%Exiv2Website: http://www.exiv2.org/
%%EndComments
%%Page: 1 1
%%EndPageComments
save
%%IncludeDocument: dummy_document.eps
restore
10 setlinewidth
10 10 moveto
0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath
stroke
%%EOF

View File

@ -0,0 +1,74 @@
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 5 105 105
%%DocumentNeededResources: dummy_document.eps
%%LanguageLevel: 2
%ADO_ContainsXMP: MainFirst
%%Pages: 1
%Exiv2Version: _Exiv2Version_
%Exiv2Website: http://www.exiv2.org/
%%EndComments
%%Page: 1 1
%%EndPageComments
%%BeginPageSetup
%Exiv2BeginXMP: Before %%EndPageSetup
/currentdistillerparams where
{pop currentdistillerparams /CoreDistVersion get 5000 lt} {true} ifelse
{userdict /Exiv2_pdfmark /cleartomark load put
userdict /Exiv2_metafile_pdfmark {flushfile cleartomark} bind put}
{userdict /Exiv2_pdfmark /pdfmark load put
userdict /Exiv2_metafile_pdfmark {/PUT pdfmark} bind put} ifelse
[/NamespacePush Exiv2_pdfmark
[/_objdef {Exiv2_metadata_stream} /type /stream /OBJ Exiv2_pdfmark
[{Exiv2_metadata_stream} 2 dict begin
/Type /Metadata def /Subtype /XML def currentdict end /PUT Exiv2_pdfmark
[{Exiv2_metadata_stream}
currentfile 0 (% &&end XMP packet marker&&)
/SubFileDecode filter Exiv2_metafile_pdfmark
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:test="http://www.example.com/"
test:test="TEST"/>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
% &&end XMP packet marker&&
[/Document 1 dict begin
/Metadata {Exiv2_metadata_stream} def currentdict end /BDC Exiv2_pdfmark
%Exiv2EndXMP
%%EndPageSetup
save
%%IncludeDocument: dummy_document.eps
restore
10 setlinewidth
10 10 moveto
0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath
stroke
%%PageTrailer
%Exiv2BeginXMP: After %%PageTrailer
[/EMC Exiv2_pdfmark
[/NamespacePop Exiv2_pdfmark
%Exiv2EndXMP
%%EOF

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?>

View File

@ -291,6 +291,31 @@ Exit code: 0
Command: exiv2 -f -ex eps-flat_minimal_exiftool-8.56.eps
Exit code: 0
-----> eps-flat_minimal_includeresource.eps <-----
Command: exiv2 -u -pa eps-flat_minimal_includeresource.eps
Exit code: 253
Command: exiv2 -dx eps-flat_minimal_includeresource.eps
Exit code: 0
Command: exiv2 -f -ex eps-flat_minimal_includeresource.eps
Exit code: 0
Restore: eps-flat_minimal_includeresource.eps
Command: exiv2 -f -eX eps-flat_minimal_includeresource.eps
Exit code: 0
Command: exiv2 -ix eps-flat_minimal_includeresource.eps
Exit code: 0
Command: (2) exiv2 -ix eps-flat_minimal_includeresource.eps
Exit code: 0
Command: exiv2 -f -ex eps-flat_minimal_includeresource.eps
Exit code: 0
-----> eps-flat_minimal_irremovable-xmp-after-endpagesetup.eps <-----
Command: exiv2 -u -pa eps-flat_minimal_irremovable-xmp-after-endpagesetup.eps
@ -3523,13 +3548,71 @@ Exit code: 0
Command: exiv2 -f -ex eps-flat_photoshop-e9-win_exiv2.eps
Exit code: 0
-----> eps-nested_minimal_begindocument-at-page-start.eps <-----
Command: exiv2 -u -pa eps-nested_minimal_begindocument-at-page-start.eps
Warning: Nested document at invalid position (before explicit or implicit EndPageSetup): 51
Exiv2 exception in print action for file eps-nested_minimal_begindocument-at-page-start.eps:
Failed to read image data
Exit code: 1
-----> eps-nested_minimal_begindocument.eps <-----
Command: exiv2 -u -pa eps-nested_minimal_begindocument.eps
Warning: Nested documents are currently not supported. Found nested document at position: 56
Exiv2 exception in print action for file eps-nested_minimal_begindocument.eps:
Failed to read image data
Exit code: 1
-----> eps-nested_minimal_includedocument-at-page-start.eps <-----
Command: exiv2 -u -pa eps-nested_minimal_includedocument-at-page-start.eps
Exit code: 253
Command: exiv2 -dx eps-nested_minimal_includedocument-at-page-start.eps
Exit code: 0
Command: exiv2 -f -ex eps-nested_minimal_includedocument-at-page-start.eps
Exit code: 0
Restore: eps-nested_minimal_includedocument-at-page-start.eps
Command: exiv2 -f -eX eps-nested_minimal_includedocument-at-page-start.eps
Exit code: 0
Command: exiv2 -ix eps-nested_minimal_includedocument-at-page-start.eps
Exit code: 0
Command: (2) exiv2 -ix eps-nested_minimal_includedocument-at-page-start.eps
Exit code: 0
Command: exiv2 -f -ex eps-nested_minimal_includedocument-at-page-start.eps
Exit code: 0
-----> eps-nested_minimal_includedocument.eps <-----
Command: exiv2 -u -pa eps-nested_minimal_includedocument.eps
Warning: Unable to handle PostScript %%Include DSC comments yet. Please provide your sample EPS file to the Exiv2 project: http://dev.exiv2.org/projects/exiv2
Exiv2 exception in print action for file eps-nested_minimal_includedocument.eps:
Failed to read image data
Exit code: 1
Exit code: 253
Command: exiv2 -dx eps-nested_minimal_includedocument.eps
Exit code: 0
Command: exiv2 -f -ex eps-nested_minimal_includedocument.eps
Exit code: 0
Restore: eps-nested_minimal_includedocument.eps
Command: exiv2 -f -eX eps-nested_minimal_includedocument.eps
Exit code: 0
Command: exiv2 -ix eps-nested_minimal_includedocument.eps
Exit code: 0
Command: (2) exiv2 -ix eps-nested_minimal_includedocument.eps
Exit code: 0
Command: exiv2 -f -ex eps-nested_minimal_includedocument.eps
Exit code: 0
-----> eps-nested_noxmp_ai-3-lev2.eps <-----