You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xmlgraphics.apache.org by Thomas Smith <th...@gmail.com> on 2012/03/06 20:07:08 UTC

How to use native text with EPSDocumentGraphics2D?

Hi,

I'd like to use XML Graphics Commons's EPSDocumentGraphics2D to generate
output that includes the text as text, not as rendered shapes.  Is there a
straightforward way to do that?

I've tried including both xmlgraphics-commons-1.4.jar and fop-1.0.jar in my
project, and using the NativeTextHandler class from org.apache.fop.render.ps,
like this...

 OutputStream out = new FileOutputStream("mini-test.eps");
EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
g2d.setGraphicContext(new GraphicContext());
g2d.setCustomTextHandler(new NativeTextHandler(g2d, null));
g2d.setupDocument(out, 200, 100);
g2d.setFont(new Font("Helvetica", Font.PLAIN, 12));
g2d.drawString("Hi there", 50, 50);
g2d.finish();
out.close();

But it generates invalid EPS files, like the one attached.  Here's the
output from Adobe Acrobat Pro...

%%[ Error: typecheck; OffendingCommand: findfont ]%%

Stack:
/Font
-null-


%%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
%%[ Warning: PostScript error. No PDF file produced. ] %%


If I leave out the NativeTextHandler line, it generates valid EPS files,
but you can't e.g. copy and paste the text from the file.

Any help appreciated!
I'm not on the mailing list, so please CC me...
-Thomas

Re: How to use native text with EPSDocumentGraphics2D?

Posted by Thomas Smith <th...@gmail.com>.
Hi,
Rendering text as text is important because the output files get
unreasonably huge and slow otherwise.  This is a requirement for my
application, and I can't figure out how to do it with the Apache libraries.
 So I gave up on all y'all and found out that this is quite easy in FreeHEP.

    UserProperties p = new UserProperties();
    p.setProperty(PSGraphics2D.TEXT_AS_SHAPES,false);
    VectorGraphics g = new PSGraphics2D(new File("BLAH-freehep.ps"), new
Dimension(layout.getWidth(), layout.getHeight()));
    g.setProperties(p);
    g.startExport();
    g.drawString("Hi there", 50, 50);
    g.endExport();
    g.dispose();

Also, I tried to export to SVG through Batik (1.7) with SVGGraphics2D, and
when I did a drawString of a string with an apostrophe in it, it didn't
escape the apostrophe and so it produced SVG that Chrome refused to render.
 I wonder if there's an XSS vulnerability buried in there, improper
escaping is bad news.
-Thomas

Re: How to use native text with EPSDocumentGraphics2D?

Posted by Thomas Smith <th...@gmail.com>.
OK, where should I ask?  Thank you!
-Thomas

Re: How to use native text with EPSDocumentGraphics2D?

Posted by Luis Bernardo <lm...@gmail.com>.
There is bug that makes the EPS file invalid. Until the bug is fixed you 
can manually fix the EPS file.

The problem is with the font. For the example below open the EPS file 
and search for

null 12 F

replace that with

/Helvetica 12 F


On 3/6/12 7:07 PM, Thomas Smith wrote:
> Hi,
>
> I'd like to use XML Graphics Commons's EPSDocumentGraphics2D to 
> generate output that includes the text as text, not as rendered 
> shapes.  Is there a straightforward way to do that?
>
> I've tried including both xmlgraphics-commons-1.4.jar and fop-1.0.jar 
> in my project, and using the NativeTextHandler class from 
> org.apache.fop.render.ps <http://org.apache.fop.render.ps>, like this...
>
> OutputStream out = new FileOutputStream("mini-test.eps");
> EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
> g2d.setGraphicContext(new GraphicContext());
> g2d.setCustomTextHandler(new NativeTextHandler(g2d, null));
> g2d.setupDocument(out, 200, 100);
> g2d.setFont(new Font("Helvetica", Font.PLAIN, 12));
> g2d.drawString("Hi there", 50, 50);
> g2d.finish();
> out.close();
>
> But it generates invalid EPS files, like the one attached.  Here's the 
> output from Adobe Acrobat Pro...
>
> %%[ Error: typecheck; OffendingCommand: findfont ]%%
>
> Stack:
> /Font
> -null-
>
>
> %%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
> %%[ Warning: PostScript error. No PDF file produced. ] %%
>
>
> If I leave out the NativeTextHandler line, it generates valid EPS 
> files, but you can't e.g. copy and paste the text from the file.
>
> Any help appreciated!
> I'm not on the mailing list, so please CC me...
> -Thomas
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: general-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: general-help@xmlgraphics.apache.org