6

In this anser, I suggested using morbusg's solution to produce outlined text with XeLaTeX. This does what it says on the tin:

\documentclass{article}
\begin{document}
% ref https://tex.stackexchange.com/a/108348/ by morbusg
\special{pdf:bcolor [.8 0 .8] [0]} % two arrays: first defines fill, second the stroke.
% If array has one entry, it's meaning grayscale, if three: RGB, if four: CMYK.
\special{pdf:literal direct .4 w 2 Tr} % .4 here is the stroke width
Here is some text.
\end{document}

contoured text

which is great.

However, now Artefact2 wants not only to turn the effect on but, of all extravagant things, to switch it off as well and, although I can come up with methods which work, I'm not sure which, if any is correct.

How should the effect be switched off?

\special{pdf:bcolor [0] [0]} 
\special{pdf:literal direct 0 w 0 Tr}

works. So does replacing the first line with

\special{pdf:bcolor 0}

which I think might be better, based on my attempt to interpret http://project.ktug.org/dvipdfmx/doc/tug2005.pdf. But, really, I have no idea.

If there is a standard reference or manual for checking this kind of thing, I would be especially grateful for a pointer.

Also, I have no idea how this should be tagged ....

cfr
  • 198,882

2 Answers2

4

For color since you started with bcolor best just to pop the stack with \special{pdf:ecolor} for the transform you've use literal pdf which makes things a bit more interesting, you could use q and Q to save and restore the graphic state but that will lose the current position unless you do them at the same point which is easy if you restrict to a horizontal box, harder if you need to account for line breaking

Also beware your space characters before your %

enter image description here

\documentclass{article}
\begin{document}
% ref http://tex.stackexchange.com/a/108348/ by morbusg
\leavevmode
\special{pdf:literal q}\special{pdf:bcolor [.8 0 .8] [0]}% two arrays: first defines fill, second the stroke.
% If array has one entry, it's meaning grayscale, if three: RGB, if four: CMYK.
\special{pdf:literal direct .4 w 2 Tr}% .4 here is the stroke width
\setbox0\hbox{Here is some text.}%
\usebox0\special{pdf:ecolor}\special{pdf:literal Q}\kern\wd0{}\
more text
\end{document}
David Carlisle
  • 757,742
  • Thanks. So how would you do it not restricted to an hbox? – cfr Feb 18 '17 at 00:40
  • @cfr too late at night for that:-) I could add something at the weekend but for the specific case of Tr I think undoing it with 0 Tr as in the other answer is probably the thing to do so you don't need the q, Q sledgehammer. – David Carlisle Feb 18 '17 at 01:24
  • How different is that from what was in my question? And it is the weekend by the time you read this :-). – cfr Feb 18 '17 at 03:06
4

If you look at the slide 11, the command for restoring the last saved color is:

\special{pdf:ecolor}

Here's my working solution:

% StrokeColor, FillColor, StrokeWidth, Text
\newcommand*{\fillstroke}[4]{%
% ref: http://tex.stackexchange.com/a/225639/125447
% Tr: rendering mode (0=Fill, 1=Stroke, 2=FillThenStroke)
% w: stroke width
\special{pdf:bcolor #1 #2}%
\special{pdf:literal direct #3 w 2 Tr}%
#4%
% ref: http://project.ktug.org/dvipdfmx/doc/tug2005.pdf
\special{pdf:ecolor}%
\special{pdf:literal direct 0 Tr}%
}
Artefact2
  • 141
  • I saw that. But how do you know what the last saved colour is? – cfr Feb 18 '17 at 00:38
  • 1
    @cfr you don't need to know, ecolor should just pop the colour back to what it was, – David Carlisle Feb 18 '17 at 01:20
  • @DavidCarlisle Well how does it know what it was, then? – cfr Feb 18 '17 at 01:22
  • the driver is maintaining a stack, bcolor pushes the existing color on to a stack sets the specified colour and then ecolor pops the stack. you should use the bxx and exx specials in pairs or bad thing happen – David Carlisle Feb 18 '17 at 01:26