You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Herve Girod <he...@gmail.com> on 2011/04/14 00:14:02 UTC

Some questions for the use of HSLF API

Hello,

I'm using the HSLF API for some time now, and it works very well, but I have
some questions on some things I can't do. I do'nt know if it's because the
API is (still) incomplete on some areas, or just if I'm not using it well.
My questions are:
- Is it possible to embed Fonts in a PowerPoint file by using the API? It's
possible to do it by using an existing PowerPoint file master, but I would
like to do it when I encounter a Font which does not exist in the
FontCollection. For example is it possible to create a new PPFont "from
scratch" using an existing TTF file, and add it to the collection?
- Is it possible to group Shapes? I tried to use ShapeGroups, but the
resulting PPT file still did not have groups of Shapes

And finally, is it possible to add image data to the slides. I tried the
following approach, but it did not work (no exception, but no image either):

    public boolean drawImage(Image image, int dx1, int dy1, int dx2, int
dy2, int sx1, int sy1,  int sx2, int sy2, Color color1, ImageObserver
observer) {
        Rectangle rectangle = new Rectangle(sx1, sy1, sx2 - sx1, sy2 - sy1);
        Shape shape = trans.createTransformedShape(rectangle);
        Rectangle rec = shape.getBounds();
        addImage(image, rec);

        return true;
    }

    private void addImage(Image image, Rectangle rec) {
        SlideShow show = slide.getSlideShow();
        if (image instanceof RenderedImage) {
            try {
                byte[] b = getImageData((RenderedImage)image);
                int idx = show.addPicture(b, Picture.PNG);
                Picture pict = new Picture(idx);
                pict.setAnchor(rec);
                slide.addShape(pict);
            } catch (IOException e) {
            }
        }
    }

    private byte[] getImageData(RenderedImage image) throws IOException {
        ByteArrayOutputStream stream = new ByteArrayOutputStream(100);
        ImageIO.write(image, "png", stream);
        stream.close();

        return stream.toByteArray();
    }


FYI, I have developed a Graphics2D drop-in which draw in a PPT context a
Swing hierarchy, and apart from these problems and other small bugs, it
works well. The project is here: https://sourceforge.net/projects/j661/

Thanks!!

Herve Girod

Re: Some questions for the use of HSLF API

Posted by Hervé Girod <he...@gmail.com>.
Ok, I solved my problem with images, but I still have the other questions ;)

Sent from my iPhone

On 14 avr. 2011, at 00:14, Herve Girod <he...@gmail.com> wrote:

> Hello,
> 
> I'm using the HSLF API for some time now, and it works very well, but I have some questions on some things I can't do. I do'nt know if it's because the API is (still) incomplete on some areas, or just if I'm not using it well. My questions are:
> - Is it possible to embed Fonts in a PowerPoint file by using the API? It's possible to do it by using an existing PowerPoint file master, but I would like to do it when I encounter a Font which does not exist in the FontCollection. For example is it possible to create a new PPFont "from scratch" using an existing TTF file, and add it to the collection?
> - Is it possible to group Shapes? I tried to use ShapeGroups, but the resulting PPT file still did not have groups of Shapes
> 
> And finally, is it possible to add image data to the slides. I tried the following approach, but it did not work (no exception, but no image either):
> 
>     public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,  int sx2, int sy2, Color color1, ImageObserver observer) {
>         Rectangle rectangle = new Rectangle(sx1, sy1, sx2 - sx1, sy2 - sy1);
>         Shape shape = trans.createTransformedShape(rectangle);
>         Rectangle rec = shape.getBounds();
>         addImage(image, rec);
> 
>         return true;
>     }
> 
>     private void addImage(Image image, Rectangle rec) {
>         SlideShow show = slide.getSlideShow();
>         if (image instanceof RenderedImage) {
>             try {
>                 byte[] b = getImageData((RenderedImage)image);
>                 int idx = show.addPicture(b, Picture.PNG);
>                 Picture pict = new Picture(idx);
>                 pict.setAnchor(rec);
>                 slide.addShape(pict);
>             } catch (IOException e) {
>             }
>         }
>     }
> 
>     private byte[] getImageData(RenderedImage image) throws IOException {
>         ByteArrayOutputStream stream = new ByteArrayOutputStream(100);
>         ImageIO.write(image, "png", stream);
>         stream.close();
>         
>         return stream.toByteArray();
>     }
> 
> 
> FYI, I have developed a Graphics2D drop-in which draw in a PPT context a Swing hierarchy, and apart from these problems and other small bugs, it works well. The project is here: https://sourceforge.net/projects/j661/
> 
> Thanks!!
> 
> Herve Girod

Re: Some questions for the use of HSLF API

Posted by Herve Girod <he...@gmail.com>.
Hello,

OK, I now only have one remaining question, as I was able to fill shapes
with images after some thought. I am not able to use  the alpha value, for
solid colors nor for pictures. The resulting fill is always solid, whatever
I try to do (for example, even if I try to use the escher properties to
force the transparency value).

Is it possible to use colors or textures with an alpha channel in POI, or do
colors or textures are always solid in the API?

Herve

2011/4/15 Hervé Girod <he...@gmail.com>

> Thanks a lot!
>
> After some thoughts, I have a question about images. When I encounter a
> paint which is not a Color, the subsequent shapes are filled in a
> bufferedImage, then a Fill is created with the resulting stream, and added
> to the SlideShow. However, if I open the resulting PPT file, there is
> effectively a Picture, but this Picture is broken.
>
> However, If I create Pictures with the same kind of streams, and add them
> to the SlideShow, it's working OK.
>
> Is my way of doing legit? I don't want to create Picture Objects in this
> case, because I want to fill only the Shape with the paint data, not just
> the overall bounding rectangle.
>
> Herve
>
> Sent from my iPhone
>
> On 15 avr. 2011, at 19:53, Yegor Kozlov <ye...@dinom.ru> wrote:
>
> >> - Is it possible to embed Fonts in a PowerPoint file by using the API?
> It's
> >> possible to do it by using an existing PowerPoint file master, but I
> would
> >> like to do it when I encounter a Font which does not exist in the
> >> FontCollection. For example is it possible to create a new PPFont "from
> >>
> >
> > HSLF does not support embedding of fonts, you can only reference external
> > fonts by name.
> >
> >
> >> scratch" using an existing TTF file, and add it to the collection?
> >> - Is it possible to group Shapes? I tried to use ShapeGroups, but the
> >> resulting PPT file still did not have groups of Shapes
> >>
> >
> > Yes, you can do that.
> >
> > There are many examples in the HSLF unit tests, for example,
> >
> https://svn.apache.org/repos/asf/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java#
> > testShapeGroup()
> >
> >
> > Regards,
> > Yegor
>

Re: Some questions for the use of HSLF API

Posted by Hervé Girod <he...@gmail.com>.
Thanks a lot!

After some thoughts, I have a question about images. When I encounter a paint which is not a Color, the subsequent shapes are filled in a bufferedImage, then a Fill is created with the resulting stream, and added to the SlideShow. However, if I open the resulting PPT file, there is effectively a Picture, but this Picture is broken. 

However, If I create Pictures with the same kind of streams, and add them to the SlideShow, it's working OK.

Is my way of doing legit? I don't want to create Picture Objects in this case, because I want to fill only the Shape with the paint data, not just the overall bounding rectangle.

Herve

Sent from my iPhone

On 15 avr. 2011, at 19:53, Yegor Kozlov <ye...@dinom.ru> wrote:

>> - Is it possible to embed Fonts in a PowerPoint file by using the API? It's
>> possible to do it by using an existing PowerPoint file master, but I would
>> like to do it when I encounter a Font which does not exist in the
>> FontCollection. For example is it possible to create a new PPFont "from
>> 
> 
> HSLF does not support embedding of fonts, you can only reference external
> fonts by name.
> 
> 
>> scratch" using an existing TTF file, and add it to the collection?
>> - Is it possible to group Shapes? I tried to use ShapeGroups, but the
>> resulting PPT file still did not have groups of Shapes
>> 
> 
> Yes, you can do that.
> 
> There are many examples in the HSLF unit tests, for example,
> https://svn.apache.org/repos/asf/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java#
> testShapeGroup()
> 
> 
> Regards,
> Yegor

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Some questions for the use of HSLF API

Posted by Yegor Kozlov <ye...@dinom.ru>.
> - Is it possible to embed Fonts in a PowerPoint file by using the API? It's
> possible to do it by using an existing PowerPoint file master, but I would
> like to do it when I encounter a Font which does not exist in the
> FontCollection. For example is it possible to create a new PPFont "from
>

HSLF does not support embedding of fonts, you can only reference external
fonts by name.


> scratch" using an existing TTF file, and add it to the collection?
> - Is it possible to group Shapes? I tried to use ShapeGroups, but the
> resulting PPT file still did not have groups of Shapes
>

Yes, you can do that.

There are many examples in the HSLF unit tests, for example,
https://svn.apache.org/repos/asf/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java#
testShapeGroup()


Regards,
Yegor