792
805
% if the CTM had been unity.
793
806
currentlinewidth dup
794
807
matrix defaultmatrix idtransform TextSaveMatrix dtransform
798
% non-square scaling reduces to Text matrix in pdfwrite , so
799
% we can ignore it. (wrong answer, but consistent)
800
pop pop currentlinewidth
802
.swapcolors show .swapcolors setlinewidth} bind
811
% non-square scaling reduces to Text matrix in pdfwrite , so
812
% we can ignore it. (wrong answer, but consistent)
813
pop pop currentlinewidth
815
show setlinewidth} bind
803
816
% 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
{ currentlinewidth exch setstrokestate
818
% Need to set the stroke width to a value which gives the correct
819
% width under pdfwrite. Pdfwrite uses (in text mode) an identity
820
% CTM, so we need to calculate the stroke width which would result
821
% if the CTM had been unity.
823
matrix defaultmatrix idtransform TextSaveMatrix dtransform
827
% non-square scaling reduces to Text matrix in pdfwrite , so
828
% we can ignore it. (wrong answer, but consistent)
829
pop pop currentlinewidth
831
setfillstate show setlinewidth} bind
817
832
% Tr 3 - Neither fill nor stroke
818
833
{ setfillstate show } bind
835
% pdfwrite emits all text inside a gsave/grestore pair. As
836
% a result we can't preserve any of the 'clip' modes, as the
837
% clip gets undone by the restore. We need to handle the clip
819
840
% Tr 4 - Fill, add to clip
820
841
{ gsave 0 .settextrenderingmode
821
842
setfillstate dup show grestore //true charpath } bind
822
843
% Tr 5 - Stroke, add to clip
823
844
{ gsave 1 .settextrenderingmode
824
setstrokestate dup .swapcolors show .swapcolors grestore
825
//true charpath } bind
846
matrix defaultmatrix idtransform TextSaveMatrix dtransform
850
% non-square scaling reduces to Text matrix in pdfwrite , so
851
% we can ignore it. (wrong answer, but consistent)
852
pop pop currentlinewidth
854
setstrokestate dup show grestore
855
//true charpath} bind
826
856
% 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
857
{ gsave 2 .settextrenderingmode
859
matrix defaultmatrix idtransform TextSaveMatrix dtransform
863
% non-square scaling reduces to Text matrix in pdfwrite , so
864
% we can ignore it. (wrong answer, but consistent)
865
pop pop currentlinewidth
867
setstrokestate setfillstate dup show grestore
868
//true charpath} bind
837
869
% Tr 7 - Add to clip
838
{ //true charpath } bind
870
{ //true charpath} bind
873
/setstrokeforTrpreservation {
874
% Check to see if the current device supports Tr
875
currentdevice 1 dict dup /PreserveTrMode dup put .getdeviceparams
876
dup type /booleantype eq not {cleartomark //false}{3 1 roll cleartomark}ifelse
878
TextRenderingMode 1 eq TextRenderingMode 2 eq or
879
TextRenderingMode 5 eq TextRenderingMode 6 eq or or {
881
% Need to set the stroke width to a value which gives the correct
882
% width under pdfwrite. Pdfwrite uses (in text mode) an identity
883
% CTM, so we need to calculate the stroke width which would result
884
% if the CTM had been unity. NOTE! Only interested in magnitudes,
887
matrix defaultmatrix idtransform TextSaveMatrix dtransform
891
% non-square scaling reduces to Text matrix in pdfwrite , so
892
% we can ignore it. (wrong answer, but consistent)
893
pop pop currentlinewidth
842
901
{ WordSpacing 0 eq TextSpacing 0 eq and FontMatrixNonHV not and
844
903
% Check to see if the current device supports Tr
845
904
currentdevice 1 dict dup /PreserveTrMode dup put .getdeviceparams
846
905
dup type /booleantype eq not {cleartomark //false}{3 1 roll cleartomark}ifelse
848
pdfwrite_textrenderingprocs TextRenderingMode get
851
TextRenderingMode 0 eq {
907
pdfwrite_textrenderingprocs TextRenderingMode get
910
TextRenderingMode 0 eq {
852
911
{ setfillstate show }
854
913
TextRenderingMode 3 eq {
879
940
{ //false charpath textrenderingprocs TextRenderingMode get exec }
884
{ TextRenderingMode 0 eq TextRenderingMode 3 eq or
885
% Tr was set to graphic state.
946
% If we are doing a plain old fill, or no text at all, *or* we are going to
947
% a device supporting text rendering modes, then go through this route.
949
TextRenderingMode 0 eq TextRenderingMode 3 eq or
950
currentdevice 1 dict dup /PreserveTrMode dup put .getdeviceparams
951
dup type /booleantype eq not {cleartomark //false}{3 1 roll cleartomark}ifelse
952
% pdfwrite can't handle rendering modes which involve clipping
953
TextRenderingMode 4 lt and or
954
% Tr was set to graphic state.
958
% preserve current line width around possible stroke setup
959
currentlinewidth exch
960
setstrokeforTrpreservation
889
962
[ TextSpacing WordSpacing 3 index
890
963
{ % str [... weach wword c undef|ythis xthis|undef
901
974
{ xshow } { yshow } Vexch pop exec
905
{ { setfillstate TextSpacing 0 Vexch 3 -1 roll ashow } }
907
{ { setfillstate WordSpacing 0 Vexch 32 4 -1 roll widthshow } }
908
{ { setfillstate WordSpacing 0 Vexch 32
909
TextSpacing 0 Vexch 6 -1 roll awidthshow } }
980
% preserve current line width around possible stroke setup
981
% This *should* work the same as the others by using
982
% currentlinewidth...setlinewidth, but it doesn't. In particular
983
% Bug688796b.pdf throws an error. I am unabel to understand why.
986
/SaveLW currentlinewidth def end
988
setstrokeforTrpreservation
989
setfillstate TextSpacing 0 Vexch 3 -1 roll ashow
998
% preserve current line width around possible stroke setup
999
currentlinewidth exch
1000
setstrokeforTrpreservation
1001
setfillstate WordSpacing 0 Vexch 32 4 -1 roll widthshow
1005
% preserve current line width around possible stroke setup
1006
currentlinewidth exch
1007
setstrokeforTrpreservation
1008
setfillstate WordSpacing 0 Vexch 32
1009
TextSpacing 0 Vexch 6 -1 roll awidthshow
915
{ { WordSpacing TextSpacing
1018
{ currentlinewidth exch
1019
WordSpacing TextSpacing
916
1020
% Implement the combination of t3 and false charpath.
917
1021
% Note that we must use cshow for this, because we
918
1022
% can't parse multi-byte strings any other way.
922
1026
% Stack: str wword wchar ccode xthis ythis
923
1027
Vexch pop currentpoint 6 3 roll
924
1028
% Stack: str wthis xorig yorig wword wchar ccode
925
(x) dup 0 3 index put //false charpath
1029
(x) dup 0 3 index put
1031
% for devices which can handle the text rendering mode we don't want
1032
% to decompose into paths, we want to do a 'show'. However pdfwrite
1033
% can't handle clipping text, so we *do* want to do the clip path
1034
% as a 'true charpath'.
1036
currentdevice 1 dict dup /PreserveTrMode dup put .getdeviceparams
1037
dup type /booleantype eq not {cleartomark //false}{3 1 roll cleartomark}ifelse {
1038
% NB we must have Tr at least 4 or the test above would have
1039
% taken a different path, so we *know* the Tr involves clipping
1040
% or we wouldn't be here. Subtract 4 from the Tr and preserve
1041
% that mode, then do a charpath so the clip path gets set up
1043
gsave TextRenderingMode 4 sub .settextrenderingmode
1044
setstrokeforTrpreservation
1045
setstrokestate setfillstate dup show grestore} if
926
1047
3 copy 32 eq { add } { exch pop } ifelse
927
1048
% Stack: str wthis xorig yorig wword wchar ccode wextra
928
1049
7 -3 roll moveto add