Adds support for all the basic graphic state operators

This commit is contained in:
= 2011-09-23 14:37:44 -07:00
parent 37a980ca28
commit 630c98052e
3 changed files with 180 additions and 5 deletions

74
pdf.js
View File

@ -4791,7 +4791,65 @@ var CanvasGraphics = (function canvasGraphics() {
TODO('set flatness: ' + flatness);
},
setGState: function canvasGraphicsSetGState(dictName) {
TODO('set graphics state from dict: ' + dictName);
var extGState = this.xref.fetchIfRef(this.res.get('ExtGState'));
if (IsDict(extGState) && extGState.has(dictName.name)) {
var gsState = this.xref.fetchIfRef(extGState.get(dictName.name));
var self = this;
gsState.forEach(function(key, value) {
switch (key) {
case 'Type':
break;
case 'LW':
self.setLineWidth(value);
break;
case 'LC':
self.setLineCap(value);
break;
case 'LJ':
self.setLineJoin(value);
break;
case 'ML':
self.setMiterLimit(value);
break;
case 'D':
self.setDash(value[0], value[1]);
break;
case 'RI':
self.setRenderingIntent(value);
break;
case 'FL':
self.setFlatness(value);
break;
case 'Font':
self.setFont(value[0], value[1]);
break;
case 'OP':
case 'op':
case 'OPM':
case 'BG':
case 'BG2':
case 'UCR':
case 'UCR2':
case 'TR':
case 'TR2':
case 'HT':
case 'SM':
case 'SA':
case 'BM':
case 'SMask':
case 'CA':
case 'ca':
case 'AIS':
case 'TK':
TODO('graphic state operator ' + key);
break;
default:
warn('Unknown graphic state operator ' + key);
break;
}
});
}
},
save: function canvasGraphicsSave() {
this.ctx.save();
@ -4958,11 +5016,17 @@ var CanvasGraphics = (function canvasGraphics() {
this.current.leading = -leading;
},
setFont: function canvasGraphicsSetFont(fontRef, size) {
var font = this.xref.fetchIfRef(this.res.get('Font'));
if (!IsDict(font))
return;
var font;
// the tf command uses a name, but graphics state uses a reference
if (IsName(fontRef)) {
font = this.xref.fetchIfRef(this.res.get('Font'));
if (!IsDict(font))
return;
font = font.get(fontRef.name);
font = font.get(fontRef.name);
} else if (IsRef(fontRef)) {
font = fontRef;
}
font = this.xref.fetchIfRef(font);
if (!font)
error('Referenced font is not found');

105
test/pdfs/extgstate.pdf Normal file
View File

@ -0,0 +1,105 @@
%PDF-1.4
%öäüß
1 0 obj
<<
/Type /Catalog
/Version /1.4
/Pages 2 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/Kids [3 0 R]
/Count 1
>>
endobj
3 0 obj
<<
/Type /Page
/MediaBox [0 0 612 792]
/Resources 4 0 R
/Parent 2 0 R
/Contents 5 0 R
>>
endobj
4 0 obj
<<
/ExtGState 6 0 R
/Font 7 0 R
/XObject <<
>>
>>
endobj
5 0 obj
<<
/Length 8 0 R
>>
stream
/GS1 gs
/F0 12 Tf
BT
100 700 Td
(I should be courier!) Tj
ET
50 600 m
400 600 l
S
endstream
endobj
6 0 obj
<<
/GS1 9 0 R
>>
endobj
7 0 obj
<<
/F0 10 0 R
>>
endobj
8 0 obj
82
endobj
9 0 obj
<<
/Type /ExtGState
/LW 10
/LC 1
/LJ 2
/ML 0.3000000119
/D [[0.0917000026 183.3300018311]
0]
/Font [10 0 R 36]
>>
endobj
10 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Courier
/Encoding /WinAnsiEncoding
>>
endobj
xref
0 11
0000000000 65535 f
0000000015 00000 n
0000000078 00000 n
0000000135 00000 n
0000000239 00000 n
0000000304 00000 n
0000000441 00000 n
0000000473 00000 n
0000000505 00000 n
0000000523 00000 n
0000000653 00000 n
trailer
<<
/Root 1 0 R
/ID [<BFFF29B7D1C75EC69AC080682C2AFC5B> <BFFF29B7D1C75EC69AC080682C2AFC5B>]
/Size 11
>>
startxref
749
%%EOF

View File

@ -145,5 +145,11 @@
"link": true,
"rounds": 1,
"type": "load"
},
{ "id": "extgstate",
"file": "pdfs/extgstate.pdf",
"link": false,
"rounds": 1,
"type": "load"
}
]