Dear Gert,

first of all, as Jörg already wrote, as long as we use the TeX typesetting 
engine, we get told (from the dvi file we're reading) to output text at certain 
positions. Each character might be placed independently, or groups of 
characters might be output at once, but as soon as kerning corrections take 
place, a new text output box is created. It's just the way it is. We could try 
to combine those boxes, but we don't do that.

Due to some internal refactoring of the text handling code, we're getting 
closer to typeset text without TeX. Well, basically we have that already, we 
actually do have it for quite some time (many years) already. But starting with 
PyX 0.13 we are now able to replace the typesetting system transparently, that 
it also works for text typeset by the axis painter without changing anything in 
there, for example. Here is some crude example:

    from pyx import unit
    from pyx.config import open, format
    from pyx.font import T1font
    from pyx.font.t1file import from_PF_bytes
    from pyx.font.afmfile import AFMfile

    class UnicodeText:

        def __init__(self, fontname="cmr10", size=10):
            self.font = T1font(from_PF_bytes(open(fontname, 
[format.type1]).read()),
                               AFMfile(open(fontname, [format.afm], 
ascii=True)))
            self.size = size

        def preamble(self):
            raise NotImplemented()

        def reset(self):
            raise NotImplemented()

        def text_pt(self, x_pt, y_pt, text, **kwargs):
            return self.font.text_pt(x_pt, y_pt, text, self.size, **kwargs)

        def text(self, x, y, *args, **kwargs):
            return self.text_pt(unit.topt(x), unit.topt(y), *args, **kwargs)

Of course we would need to properly handle the formatting parameters like 
text.halign etc. from the text module ourself. Instead, in this example I pass 
additional parameters to the font text output creation, which makes it possible 
for me to access some features provided here. This is just for testing.

Let me show how to use it:

    from pyx import *

    text.set(cls=UnicodeText)

    c = canvas.canvas()
    c.text(0, 1, "Hello, world! AV")
    c.text(0, 0, "Hello, world! AV", kerning=True)
    c.writePDFfile(write_compress=False)

The result unicodetext.pdf is attached, and I disabled compression to make the 
page stream readable. As you can see, the text typeset without kerning is just 
a single output, but also the one with kerning is combined into a single text 
output with the kerning corrections embedded.

Now you can open this file in Illustrator. It will tell you (if you haven't 
installed CMR10), that the font is missing. Now you can just replace the font. 
I did so with Minion Pro Condensed as an example. Updating the artboard to the 
file content, which is another one-click operation, you get the attached output 
(without any retyping or the like). It nice to see, that this even works with 
kerning as we have inserted it as relative operations, but I guess the kerning 
correction just remains the one from the original font (to my understanding 
there is no option to do so differently, but in the end of the day I don't know 
that the Adobe Software really does here internally when changing the font). 
Anyway, the result looks promising as you can see in the second file. With this 
workflow (and using text output created on the font level, not via the TeX 
typesetting engine), I can alter the font without any retyping. By the way, I 
saved this second file without page stream compression as well, so you can just 
look inside and find out the commands used to typeset the text, which have been 
split here at kerning points by Illustrator, interestingly.

Note that all this will only work for simple text output, not for formulas. For 
the later typically the font and the font sizes are switched and the output is 
placed on various positions. This just needs to be redone for the other font. 
But for simple text like axis labels (without super-/sub-script) we could 
probably get this working that way. On the other hand this also means, that 
this workflow of replacing the font should already be possible also for text 
typeset by TeX when no kerning is active and you have single words only. In 
that case the DVI should contain groups of characters. However, every kerning 
and also every new word starts a new text output. However, you will notice that 
the output behavior of TeX in this respect depends on the font. For example the 
text in http://pyx.sourceforge.net/examples/text/font.html is typeset by 
placing each character separately, which however is not the case when using 
Computer Modern Roman. This was my observation some time ago. It might depend 
on the TeX installation in use ...

So, no solution for the moment, but it's interesting to have been informed 
about your problem and to do some tests. We probably can improve the situation 
somewhat, when typesetting with a single font and by not using TeX anymore will 
become a general feature. This is already in the making, but given the slow 
development speed of PyX, this will probably be still a few years in the future.

Best,


André

Am 13.07.2015 um 16:55 schrieb Gert-Ludwig Ingold 
<[email protected]>:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Dear André, dear Jörg,
> 
> in a figure prepared with PyX, a professional designer had to replace the
> labels because the journal is using a non-free font which I do not own.
> Since PyX relies on (La)TeX for typesetting, each character is placed
> individually and (La)TeX ensures the proper kerning. Of course, for a
> different font the kerning will be different so that simply switching the
> font is not an option. Instead, the designer had to retype the text which
> not only costs time but also introduces a potential source of errors. In
> this special case, it would be advantageous if it were possible to set
> longer text in one single box so that the designer could just switch the
> font. This may well be impossible to do with PyX, but I wonder whether
> there exists a trick which could help in this situation. Or may be I just
> oversee something obvious? Any help is appreciated.
> 
> Best regards,
> Gert
> 
> - -- 
> Gert-Ludwig Ingold     email: [email protected]
> Institut für Physik    Phone: +49-821-598-3234
> Universität Augsburg   Fax  : +49-821-598-3222
> D-86135 Augsburg       WWW  : www.physik.uni-augsburg.de/theo1/ingold
> Germany                PGP  : 86FF5A93, key available from homepage
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.12 (GNU/Linux)
> 
> iEYEARECAAYFAlWj0VoACgkQ4E2iM4b/WpPjDACeIlGDi5JSjbO96WWkyNxo5TLT
> 9tgAoJDDwo21nbqrClXeHWM/luPex2l5
> =Q1eg
> -----END PGP SIGNATURE-----
> 
> ------------------------------------------------------------------------------
> Don't Limit Your Business. Reach for the Cloud.
> GigeNET's Cloud Solutions provide you with the tools and support that
> you need to offload your IT needs and focus on growing your business.
> Configured For All Businesses. Start Your Cloud Today.
> https://www.gigenetcloud.com/
> _______________________________________________
> PyX-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pyx-user

-- 
by  _ _      _    Dr. André Wobst, Amselweg 22, 85716 Unterschleißheim
   / \ \    / )   [email protected], http://www.wobsta.de/
  / _ \ \/\/ /    PyX - High quality PostScript and PDF figures
 (_/ \_)_/\_/     with Python & TeX: visit http://pyx.sourceforge.net/

Attachment: unicodetext.pdf
Description: Adobe PDF document

Attachment: unicodetext_edited_by_illustrator.pdf
Description: Adobe PDF document

Attachment: smime.p7s
Description: S/MIME cryptographic signature

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to