You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Yegor Kozlov <ye...@dinom.ru> on 2006/07/13 16:42:14 UTC
object model to work with styles in PowerPoint
Hi All,
We (HSLF developers) are searching for good object model to work with the character and paragraph styles.
It would be good to discuss a possible architecture and know your opinions,
before we settle. Working with text is a key feature of a PowerPoint API and this discussion won't harm. :))
A possible solution to handle character styles is to use java.text.AttributedString, a standard Java class
which is meant for working with format runs in Java2D.
Use cases may look as follows:
(a) Create a text box and set character format:
org.apache.poi.hslf.model.TextRun txrun = ...; //HSLF object which represents a run of text in a powerpoint document
String text = "Hello, World";
txrun.settext(text)
AttributedString str = txrun.getCharacterStyle();
str.addAttribute(TextAttribute.FAMILY, "Arial"); //set the font family to the entire string
str.addAttribute(TextAttribute.SIZE, new Float(32), 0, 5); //set the font size to a a subrange
str.addAttribute(TextAttribute.FOREGROUND, Color.red, 3, 6);//set the font color to a a subrange
(b) For a text run read format runs or get attributes at the specified position:
org.apache.poi.hslf.model.TextRun txrun = ...;
String text = txrun.getText();
AttributedString str = txrun.getCharacterStyle();
//iterate over format runs
AttributedCharacterIterator it = str.getIterator();
int index = 0;
while (index < it.getEndIndex()) {
it.setIndex(index);
inr runLimit = it.getRunLimit();
Map attrs = it.getAttributes();
String fragment = text.substring(index , runLimit);
System.out.println("[" + fragment + "]: "+ attrs);
index = runLimit;
}
//get format attributes at the specified position:
it.setIndex(8);
Map attr = it.getAttributes();
System.out.println("attributes at position 8: " + attr);
Advantages of this approach:
- there are lots of docs on Java2D and people can use their previous experience
or read recommended books to learn more how to use java.text.AttributedString.
- This part of HSLF becomes compatible with Java graphics.
Users can use the AttributedString object to paint the string using java.awt.Graphics:
Graphics2D.drawString(AttributedCharacterIterator iterator, float x, float y)
should output something similar to what you see in PowerPoint.
- We don't need any special objects to handle stylings. (Currently we
have RichTextRun object with getters and setters for font name, font
size, bold/italic/underline, etc). All is done via the standard methods
of java.text.AttributedString.
Drawbacks:
- My main concern is that the exposing of AttributedString may not be user-friendly.
Also I'm not sure if this approach will fit for working with paragraph styles.
I think that the API to work with paragraph styles should be symmetrical, i.e.
set paragraph attributes via AttributedString:
AttributedString str = txrun.getParagraphStyle();
//do paragraph styling
So, I would like to hear you comments. Also, If anyone knows a good
alternative to the suggested architecture - please share your
knowledge.
Regards,
Yegor Kozlov
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
Re[3]: object model to work with styles in PowerPoint
Posted by Nick Burch <ni...@torchbox.com>.
On Fri, 14 Jul 2006, Yegor Kozlov wrote:
> OK. The said makes sense.
>
> I'm not sure about method signatures, need to think about it :).
I was suggesting the idea, not the name. They almost certainly need to
have a totally different name!
> Probably there will be
> getStyles(); //returns all applied styles
> and
> getStyles(int mask); //returns specific styles
Hmm, I'd probably go with
getStyles()
getStylesAll() - same as above
getStylesTextRun()
getStylesMaster()
but that's just me. If we do do the mask thing, we should have a "ALL"
mask too
> We are going to add a bunch of methods to the TextRun object, probably
> it's better to delegate calls to a special object :
I'd be happy with that - we could also shift some of the logic from
RichTextRun (for dealing with the actual StyleTextPropAtoms) there too
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
Re[3]: object model to work with styles in PowerPoint
Posted by Yegor Kozlov <ye...@dinom.ru>.
OK. The said makes sense.
I'm not sure about method signatures, need to think about it :).
Probably there will be
getStyles(); //returns all applied styles
and
getStyles(int mask); //returns specific styles
getStyles( MASTER | TEXTRUN) is equivalent of getStyles()
We are going to add a bunch of methods to the TextRun object, probably
it's better to delegate calls to a special object :
TextFormat fmt = txrun.getTextFormat();
//do formatting via TextFormat
Yegor
NB> On Fri, 14 Jul 2006, Yegor Kozlov wrote:
>>>> My worry is that your plan doesn't easily allow someone to get all the
>>>> different bits of information from the first list.
>>
>> Do users really need this information? When editing a PPT file you don't
>> care if you are overriding a master style or not. I think this
>> information is low-level and makes sense only for developers, not for
>> end-users, if only they are familiar with PPT format.
NB> One of the things I keep meaning to write is a PPT -> S5 converter.
NB> Knowing where the stylings come from would be very useful to me
NB> On other template based stuff I've worked on in the past, you always end
NB> up needing to know if some styling came from the template, or from the
NB> text.
NB> I suppose we could have:
NB> getTextSpecificStyles
NB> returns just styles for the text
NB> flagged as being allowed to edit
NB> getAllApplyingStyles
NB> gets the master ones, then applys the text ones on top
NB> flagged as being not allowed to edit
NB> getMasterStyles
NB> calls get styles on the master
NB> turns off the edit flag
NB> setTextStyles
NB> sets the text specific styles
NB> only works on edit allowed ones
NB> Then on the master
NB> getMasterStyles
NB> returns the styles from the master
NB> flagged as being allowed to edit
NB> setMasterStyles
NB> sets the master styles
NB> only works on edit allowed ones (should always be)
NB> Would that make sense?
NB> Nick
NB> ---------------------------------------------------------------------
NB> To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
NB> Mailing List: http://jakarta.apache.org/site/mail2.html#poi
NB> The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
Re[2]: object model to work with styles in PowerPoint
Posted by Nick Burch <ni...@torchbox.com>.
On Fri, 14 Jul 2006, Yegor Kozlov wrote:
>>> My worry is that your plan doesn't easily allow someone to get all the
>>> different bits of information from the first list.
>
> Do users really need this information? When editing a PPT file you don't
> care if you are overriding a master style or not. I think this
> information is low-level and makes sense only for developers, not for
> end-users, if only they are familiar with PPT format.
One of the things I keep meaning to write is a PPT -> S5 converter.
Knowing where the stylings come from would be very useful to me
On other template based stuff I've worked on in the past, you always end
up needing to know if some styling came from the template, or from the
text.
I suppose we could have:
getTextSpecificStyles
returns just styles for the text
flagged as being allowed to edit
getAllApplyingStyles
gets the master ones, then applys the text ones on top
flagged as being not allowed to edit
getMasterStyles
calls get styles on the master
turns off the edit flag
setTextStyles
sets the text specific styles
only works on edit allowed ones
Then on the master
getMasterStyles
returns the styles from the master
flagged as being allowed to edit
setMasterStyles
sets the master styles
only works on edit allowed ones (should always be)
Would that make sense?
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
Re[2]: object model to work with styles in PowerPoint
Posted by Yegor Kozlov <ye...@dinom.ru>.
>> My worry is that your plan doesn't easily allow someone to get all the
>> different bits of information from the first list.
Do users really need this information? When editing a PPT file you don't care if you are overriding a master
style or not. I think this information is low-level and
makes sense only for developers, not for end-users, if only they are
familiar with PPT format.
Could you provide a use case when such information about
could be useful? I mean a case when users wants to see what styles
come from the master and what are overridden.
>> Plus somewhere else:
>> * What text styles does this master define?
>> * Set this style on this master
Of course there will be MainMaster object to provide such information.
There is a master style per each type of text defined in
TextHeaderAtom, i.e. to query master style you need to know type of the
text:
MainMaster master = slide.getMainMaster();
//get default character styles for titles
Map props1 = master.getCharacterStyle(TextHeaderAtom.TITLE_TYPE);
//get default character styles for body
Map props2 = master.getCharacterStyle(TextHeaderAtom.BODY_TYPE);
Yegor
NB> On Thu, 13 Jul 2006, Yegor Kozlov wrote:
>> So, I would like to hear you comments.
>>>From my perspective, I think we want to offer the following on a block of
NB> text:
NB> * "How will my text look" (what's the combined styles from the master, and
NB> from the text)
NB> * What text styles does my text set in addition to the master?
NB> * What text styles does the master apply to my text?
NB> * Set this style on this text
NB> Plus somewhere else:
NB> * What text styles does this master define?
NB> * Set this style on this master
NB> My worry is that your plan doesn't easily allow someone to get all the
NB> different bits of information from the first list.
NB> How did you anticipate your scheme differentiating master vs non master,
NB> and exposing that?
NB> Nick
NB> ---------------------------------------------------------------------
NB> To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
NB> Mailing List: http://jakarta.apache.org/site/mail2.html#poi
NB> The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
Re: object model to work with styles in PowerPoint
Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 13 Jul 2006, Yegor Kozlov wrote:
> So, I would like to hear you comments.
>From my perspective, I think we want to offer the following on a block of
text:
* "How will my text look" (what's the combined styles from the master, and
from the text)
* What text styles does my text set in addition to the master?
* What text styles does the master apply to my text?
* Set this style on this text
Plus somewhere else:
* What text styles does this master define?
* Set this style on this master
My worry is that your plan doesn't easily allow someone to get all the
different bits of information from the first list.
How did you anticipate your scheme differentiating master vs non master,
and exposing that?
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/