1
1
% Copyright (C) 1994, 2000 Aladdin Enterprises. All rights reserved.
3
3
% This software is provided AS-IS with no warranty, either express or
6
6
% This software is distributed under license and may not be copied,
7
7
% modified or distributed except as expressly authorized under the terms
8
8
% of the license contained in the file LICENSE in this distribution.
10
10
% For more information about licensing, please refer to
11
11
% http://www.ghostscript.com/licensing/. For information on
12
12
% commercial licensing, go to http://www.artifex.com/licensing/ or
13
13
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14
14
% San Rafael, CA 94903, U.S.A., +1(415)492-9861.
16
% $Id: pdf_ops.ps 12302 2011-03-19 00:32:37Z ray $
17
17
% Definitions for most of the PDF operators.
19
19
.currentglobal //true .setglobal
461
461
OFFlevels length 0 eq {
462
PDFusingtransparency {
463
% knockout trans group around the filled and stroked object
465
/Isolated //true /Knockout //true
467
% strokepath will return empty path (no currentpoint) if nothing is stroked
468
gsave { strokepath pathbbox } stopped grestore not {
470
.begintransparencygroup
471
gsave setfillstate fill grestore
472
setstrokestate .swapcolors /stroke fsexec .swapcolors
473
.endtransparencygroup
474
} { newpath pop } ifelse
476
gsave setfillstate fill grestore
477
setstrokestate .swapcolors /stroke fsexec .swapcolors
462
PDFusingtransparency {
463
% knockout trans group around the filled and stroked object
465
/Isolated //true /Knockout //true
467
% strokepath will return empty path (no currentpoint) if nothing is stroked
468
gsave { strokepath pathbbox } stopped grestore not {
470
.begintransparencygroup
471
gsave setfillstate fill grestore
472
setstrokestate .swapcolors /stroke fsexec .swapcolors
473
.endtransparencygroup
474
} { newpath pop } ifelse
476
gsave setfillstate fill grestore
477
setstrokestate .swapcolors /stroke fsexec .swapcolors
487
487
OFFlevels length 0 eq {
488
PDFusingtransparency {
489
% knockout trans group around the filled and stroked object
491
/Isolated //true /Knockout //true
493
% strokepath will return empty path (no currentpoint) if nothing is stroked
494
gsave { strokepath pathbbox } stopped grestore not {
488
PDFusingtransparency {
489
% knockout trans group around the filled and stroked object
491
/Isolated //true /Knockout //true
493
% strokepath will return empty path (no currentpoint) if nothing is stroked
494
gsave { strokepath pathbbox } stopped grestore not {
495
495
1 .setopacityalpha
496
.begintransparencygroup
497
gsave setfillstate eofill grestore
498
setstrokestate .swapcolors /stroke fsexec .swapcolors
499
.endtransparencygroup
500
} { newpath pop } ifelse
502
gsave setfillstate eofill grestore
503
setstrokestate .swapcolors /stroke fsexec .swapcolors
496
.begintransparencygroup
497
gsave setfillstate eofill grestore
498
setstrokestate .swapcolors /stroke fsexec .swapcolors
499
.endtransparencygroup
500
} { newpath pop } ifelse
502
gsave setfillstate eofill grestore
503
setstrokestate .swapcolors /stroke fsexec .swapcolors
551
551
TextFont dup //null eq { pop } { setfont } ifelse
554
% The text state can be set even outside BT/ET.
554
% The text state can be set even outside BT/ET.
555
555
currentdict /TextSaveMatrix known {
556
556
TextSaveMatrix setmatrix settextmatrix
559
559
/settextposition {
560
% Update the TextMatrix translation.
560
% Update the TextMatrix translation.
561
561
gsave TextSaveMatrix setmatrix
562
562
currentpoint TextRise sub TextMatrix 4 2 getinterval astore pop
563
% We would like to do "grestore currentpoint translate"
564
% here, but some PDF files set a singular text matrix
565
% (0 0 0 0 <x> <y> Tm), so we can't do this.
563
% We would like to do "grestore currentpoint translate"
564
% here, but some PDF files set a singular text matrix
565
% (0 0 0 0 <x> <y> Tm), so we can't do this.
566
566
TextTempMatrix identmatrix setmatrix currentpoint
568
568
TextTempMatrix currentmatrix 4 2 getinterval astore pop
606
606
% Worker procedure for testing a single font matrix
607
607
/?FontMatrixNonHV { % ?horz <<fontdict>> -- ?horz ?nonhv
608
608
/FontMatrix .knownget {
609
1 index { 1 } { 2 } ifelse get 0 ne
609
1 index { 1 } { 2 } ifelse get 0 ne
614
614
% Worker procedure for recursive checking of font matrices
615
615
/?FontMatrixNonHV { % {self} ?horz <<font>> -- {self} ?horz ?nonhv
616
616
2 copy //?FontMatrixNonHV exec { % check the font's own FontMatrix
619
% look for descendents/ components
620
pop % {self} ?horz <<font>>
622
dup 0 eq { % Type 0: look into FDepVector
623
pop /FDepVector get 2 index % {self} ?horz [fonts..] {testproc}
625
9 eq { % Type 9 (CIDFontType 0): check FDArray
626
/FDArray get //?FontMatrixNonHV
627
} { % all others: nothing more to check
631
%stack: {self} ?horz [fonts..] {testproc}
632
//false 5 2 roll { % {testproc} false {self} ?horz <<subfont>>
634
4 -1 roll pop //true 4 1 roll
638
%stack: {testproc} ?nonhv {self} ?horz
619
% look for descendents/ components
620
pop % {self} ?horz <<font>>
622
dup 0 eq { % Type 0: look into FDepVector
623
pop /FDepVector get 2 index % {self} ?horz [fonts..] {testproc}
625
9 eq { % Type 9 (CIDFontType 0): check FDArray
626
/FDArray get //?FontMatrixNonHV
627
} { % all others: nothing more to check
631
%stack: {self} ?horz [fonts..] {testproc}
632
//false 5 2 roll { % {testproc} false {self} ?horz <<subfont>>
634
4 -1 roll pop //true 4 1 roll
638
%stack: {testproc} ?nonhv {self} ?horz
784
784
/pdfwrite_textrenderingprocs [
786
{ setfillstate show } bind
788
{ currentlinewidth exch setstrokestate
786
{ setfillstate show } bind
788
{ currentlinewidth exch setstrokestate
789
789
% Need to set the stroke width to a value which gives the correct
790
790
% width under pdfwrite. Pdfwrite uses (in text mode) an identity
791
791
% CTM, so we need to calculate the stroke width which would result
792
% if the CTM had been unity.
794
matrix defaultmatrix idtransform TextSaveMatrix dtransform
792
% if the CTM had been unity.
794
matrix defaultmatrix idtransform TextSaveMatrix dtransform
798
% non-square scaling reduces to Text matrix in pdfwrite , so
798
% non-square scaling reduces to Text matrix in pdfwrite , so
799
799
% we can ignore it. (wrong answer, but consistent)
800
800
pop pop currentlinewidth
801
801
}ifelse setlinewidth
802
802
.swapcolors show .swapcolors setlinewidth} bind
803
% Tr 2 - Fill then Stroke
804
{ gsave 0 .settextrenderingmode
805
setfillstate dup show currentpoint 3 -1 roll
806
grestore gsave setstrokestate
808
% We need to make sure the matrix used for the stroke
809
% and therefore stroke width does not include the
811
TextSaveMatrix setmatrix
817
% Tr 3 - Neither fill nor stroke
818
{ setfillstate show } bind
819
% Tr 4 - Fill, add to clip
820
{ gsave 0 .settextrenderingmode
821
setfillstate dup show grestore //true charpath } bind
822
% Tr 5 - Stroke, add to clip
823
{ gsave 1 .settextrenderingmode
824
setstrokestate dup .swapcolors show .swapcolors grestore
825
//true charpath } bind
826
% Tr 6 - Fill, stroke, add to clip
827
{ gsave 0 .settextrenderingmode
828
setfillstate dup show grestore gsave dup
829
setstrokestate //false charpath
830
% We need to make sure the matrix used for the stroke
831
% and therefore stroke width does not include the
833
TextSaveMatrix setmatrix
835
stroke .swapcolors grestore
836
//true charpath } bind
838
{ //true charpath } bind
803
% Tr 2 - Fill then Stroke
804
{ gsave 0 .settextrenderingmode
805
setfillstate dup show currentpoint 3 -1 roll
806
grestore gsave setstrokestate
808
% We need to make sure the matrix used for the stroke
809
% and therefore stroke width does not include the
811
TextSaveMatrix setmatrix
817
% Tr 3 - Neither fill nor stroke
818
{ setfillstate show } bind
819
% Tr 4 - Fill, add to clip
820
{ gsave 0 .settextrenderingmode
821
setfillstate dup show grestore //true charpath } bind
822
% Tr 5 - Stroke, add to clip
823
{ gsave 1 .settextrenderingmode
824
setstrokestate dup .swapcolors show .swapcolors grestore
825
//true charpath } bind
826
% Tr 6 - Fill, stroke, add to clip
827
{ gsave 0 .settextrenderingmode
828
setfillstate dup show grestore gsave dup
829
setstrokestate //false charpath
830
% We need to make sure the matrix used for the stroke
831
% and therefore stroke width does not include the
833
TextSaveMatrix setmatrix
835
stroke .swapcolors grestore
836
//true charpath } bind
838
{ //true charpath } bind
842
842
{ WordSpacing 0 eq TextSpacing 0 eq and FontMatrixNonHV not and
844
844
% Check to see if the current device supports Tr
845
845
currentdevice 1 dict dup /PreserveTrMode dup put .getdeviceparams
846
846
dup type /booleantype eq not {cleartomark //false}{3 1 roll cleartomark}ifelse
848
pdfwrite_textrenderingprocs TextRenderingMode get
851
TextRenderingMode 0 eq {
852
{ setfillstate show }
854
TextRenderingMode 3 eq {
855
% Some PDF files execute 'tm' with a singular matrix,
856
% and then use the text rendering mode 3.
857
% The graphics library currently cannot handle text
858
% operations when the CTM is singular.
859
% Work around this here.
861
matrix currentmatrix dup dup
862
dup 0 get 0 eq 1 index 1 get 0 eq and {
863
dup dup 2 get 0 eq { 0 }{ 1 } ifelse 1 put
865
dup 2 get 0 eq 1 index 3 get 0 eq and {
866
dup dup 1 get 0 eq { 3 }{ 2 } ifelse 1 put
869
2 index setfillstate show % Tr was set to graphic state.
871
% now set the currentpoint using the original matrix
874
//false charpath currentpoint newpath
879
{ //false charpath textrenderingprocs TextRenderingMode get exec }
848
pdfwrite_textrenderingprocs TextRenderingMode get
851
TextRenderingMode 0 eq {
852
{ setfillstate show }
854
TextRenderingMode 3 eq {
855
% Some PDF files execute 'tm' with a singular matrix,
856
% and then use the text rendering mode 3.
857
% The graphics library currently cannot handle text
858
% operations when the CTM is singular.
859
% Work around this here.
861
matrix currentmatrix dup dup
862
dup 0 get 0 eq 1 index 1 get 0 eq and {
863
dup dup 2 get 0 eq { 0 }{ 1 } ifelse 1 put
865
dup 2 get 0 eq 1 index 3 get 0 eq and {
866
dup dup 1 get 0 eq { 3 }{ 2 } ifelse 1 put
869
2 index setfillstate show % Tr was set to graphic state.
871
% now set the currentpoint using the original matrix
874
//false charpath currentpoint newpath
879
{ //false charpath textrenderingprocs TextRenderingMode get exec }
884
884
{ TextRenderingMode 0 eq TextRenderingMode 3 eq or
885
885
% Tr was set to graphic state.
889
889
[ TextSpacing WordSpacing 3 index
890
890
{ % str [... weach wword c undef|ythis xthis|undef
891
exch % will be removed, unless FontMatrix.xx/yy == 0 (FontMatrixNonHV already true)
891
exch % will be removed, unless FontMatrix.xx/yy == 0 (FontMatrixNonHV already true)
892
892
Vexch pop % str [... weach wword c wthis
893
893
3 index add exch 32 eq {1 index add} if % str [... weach wword w
894
894
3 1 roll % str [... w weach wword
896
896
% for the "exch" removed or not below, see comment in pdf_font.ps::getfontmetrics
897
currentfont /FontMatrix get 0 3 Vexch pop get 0 ne {
898
1 1 index length 1 sub getinterval cvx
897
currentfont /FontMatrix get 0 3 Vexch pop get 0 ne {
898
1 1 index length 1 sub getinterval cvx
901
901
{ xshow } { yshow } Vexch pop exec
905
905
{ { setfillstate TextSpacing 0 Vexch 3 -1 roll ashow } }
907
907
{ { setfillstate WordSpacing 0 Vexch 32 4 -1 roll widthshow } }
908
908
{ { setfillstate WordSpacing 0 Vexch 32
909
909
TextSpacing 0 Vexch 6 -1 roll awidthshow } }
915
915
{ { WordSpacing TextSpacing
916
% Implement the combination of t3 and false charpath.
917
% Note that we must use cshow for this, because we
918
% can't parse multi-byte strings any other way.
919
% Stack: string wword wchar
921
exch % will be removed, unless FontMatrixNonHV && FontMatrix.xx/yy == 0
922
% Stack: str wword wchar ccode xthis ythis
923
Vexch pop currentpoint 6 3 roll
924
% Stack: str wthis xorig yorig wword wchar ccode
925
(x) dup 0 3 index put //false charpath
916
% Implement the combination of t3 and false charpath.
917
% Note that we must use cshow for this, because we
918
% can't parse multi-byte strings any other way.
919
% Stack: string wword wchar
921
exch % will be removed, unless FontMatrixNonHV && FontMatrix.xx/yy == 0
922
% Stack: str wword wchar ccode xthis ythis
923
Vexch pop currentpoint 6 3 roll
924
% Stack: str wthis xorig yorig wword wchar ccode
925
(x) dup 0 3 index put //false charpath
926
926
3 copy 32 eq { add } { exch pop } ifelse
927
% Stack: str wthis xorig yorig wword wchar ccode wextra
927
% Stack: str wthis xorig yorig wword wchar ccode wextra
928
928
7 -3 roll moveto add
929
929
0 Vexch rmoveto pop
931
931
% for the "exch" removed or not below, see comment in pdf_font.ps::getfontmetrics
932
FontMatrixNonHV dup not exch {
933
currentfont /FontMatrix get 0 3 Vexch pop get 0 ne
935
1 1 index length 1 sub getinterval cvx
937
4 -1 roll cshow pop pop
938
textrenderingprocs TextRenderingMode get exec
932
FontMatrixNonHV dup not exch {
933
currentfont /FontMatrix get 0 3 Vexch pop get 0 ne
935
1 1 index length 1 sub getinterval cvx
937
4 -1 roll cshow pop pop
938
textrenderingprocs TextRenderingMode get exec