Discussion:
[pdftex] Question about \pdfincludechars
Gregory Heytings
2016-08-20 08:27:26 UTC
Permalink
Hi,

I'm trying to design a macro to include a complete font in a PDF. I tried
the following macro:

\def\includefont#1{
\count10=0
\font\f=#1
\loop
\ifnum\count10<256
\pdfincludechars\f{\char\count10}
\advance\count10by1
\repeat
}

However, instead of including all characters as I would have expected, it
includes '\', 'c', 'h', 'a', 'r', ...

I tried a number of other ways, but none of them seems to work. How could
this be done?

Thanks,

Gregory
Heiko Oberdiek
2016-08-20 12:21:40 UTC
Permalink
Hello,
Post by Gregory Heytings
I'm trying to design a macro to include a complete font in a PDF. I
\def\includefont#1{
\count10=0
\font\f=#1
\loop
\ifnum\count10<256
\pdfincludechars\f{\char\count10}
\advance\count10by1
\repeat
}
However, instead of including all characters as I would have expected,
it includes '\', 'c', 'h', 'a', 'r', ...
\pdfincludechars should include the characters directly as string
instead of commands, that would produce them for typesetting.

Example:

\def\includefont#1{%
\begingroup
\count10=0
\font\f=#1
\loop
\ifnum\count10<256
\lccode`\!=\count10
\lowercase{%
\pdfincludechars\f{!}%
}%
\advance\count10by1
\repeat
\endgroup
}

Yours sincerely
Heiko Oberdiek
Gregory Heytings
2016-08-20 13:10:33 UTC
Permalink
Post by Heiko Oberdiek
\pdfincludechars should include the characters directly as string
instead of commands, that would produce them for typesetting.
\def\includefont#1{%
\begingroup
\count10=0
\font\f=#1
\loop
\ifnum\count10<256
\lccode`\!=\count10
\lowercase{%
\pdfincludechars\f{!}%
}%
\advance\count10by1
\repeat
\endgroup
}
Thank you very much, this works... almost! The only remaining problem is
that for some reason I do not understand it does not include character at
position 0, in spite of the fact that \count10 starts at 0... Is this a
bug?

For example, if I do \includefont{cmr10} I have chars 1-127 included, if I
do \includefont{cmr10} and \char"00 somewhere else I have chars 0-127
included (as it should).

Gregory
Gregory Heytings
2016-08-21 10:56:18 UTC
Permalink
Post by Gregory Heytings
Thank you very much, this works... almost! The only remaining problem
is that for some reason I do not understand it does not include
character at position 0, in spite of the fact that \count10 starts at
0... Is this a bug?
For example, if I do \includefont{cmr10} I have chars 1-127 included, if
I do \includefont{cmr10} and \char"00 somewhere else I have chars 0-127
included (as it should).
Indeed, the TeXbook specifies that "Conversion to uppercase means that a
character is replaced by its \uccode value, unless the \uccode value is
zero (when no change is made). Conversion to lowercase is similar, using
the \lccode." So this solution:

\lccode`\!=<character position>\lowercase{\pdfincludechars\f{!}}

cannot work for character 0.

I also tried:

\catcode`\^^@=11\pdfincludechars\f{^^@}
\catcode`\^^00=11\pdfincludechars\f{^^00}
\catcode`\^^@=11\pdfincludechars\f{`^^@}
\catcode`\^^00=11\pdfincludechars\f{`^^00}
\catcode`\^^@=11\let\z=`^^@\pdfincludechars\f{\z}
\catcode`\^^00=11\let\z=`^^00\pdfincludechars\f{\z}
\catcode`\^^@=11\let\z=`^^@\def\picf{\pdfincludechars\f}\expandafter\picf\expandafter{\z}
\catcode`\^^00=11\let\z=`^^00\def\picf{\pdfincludechars\f}\expandafter\picf\expandafter{\z}
\catcode`\^^@=11\let\z=`^^@\def\picf{\pdfincludechars\f}\expandafter\expandafter\expandafter\picf\expandafter{\z}
\catcode`\^^00=11\let\z=`^^00\def\picf{\pdfincludechars\f}\expandafter\expandafter\expandafter\picf\expandafter{\z}
\catcode`\^^@=11\setbox10=\hbox{^^@}\immediate\pdfxform10
\catcode`\^^00=11\setbox10=\hbox{^^00}\immediate\pdfxform10

but none of them works. So... how should I ask pdfTeX to include
character 0 of a given font?

Gregory
Gregory Heytings
2016-08-21 14:05:14 UTC
Permalink
For the record, I answer my own question.

To force inclusion of all characters of a font, one can use the following
macro:

{\catcode`\^^@=11
\gdef\pdfincludefont#1{
\begingroup
\font\f=#1
\pdfincludechars\f{^^@}
\count10=1
\loop
\ifnum\count10<256
\lccode`\!=\count10
\lowercase{\pdfincludechars\f{!}}
\advance\count10by1
\repeat
\endgroup
}}

Gregory
Heiko Oberdiek
2016-08-23 20:30:59 UTC
Permalink
Post by Gregory Heytings
Post by Heiko Oberdiek
\pdfincludechars should include the characters directly as string
instead of commands, that would produce them for typesetting.
\def\includefont#1{%
\begingroup
\count10=0
\font\f=#1
\loop
\ifnum\count10<256
\lccode`\!=\count10
\lowercase{%
\pdfincludechars\f{!}%
}%
\advance\count10by1
\repeat
\endgroup
}
Thank you very much, this works... almost! The only remaining problem
is that for some reason I do not understand it does not include
character at position 0, in spite of the fact that \count10 starts at
0... Is this a bug?
No, I forgot, \lowercase does not change the case if \lccode is zero.
The fixed version uses the character with category code 0 instead of the
exclamation mark. Then this puts the correct character in
\pdfincludechars, when the \lccode is zero.

Yours sincerely
Heiko Oberdiek

Loading...