In order to format a single character or word in continuous text I tried
the following:

- I created a global style "superscript"


Javacode:
    private static final String SUPERSCRIPT = "superscript";
    private static final String SUBSCRIPT = "subscript";

    public static void addDocumentStyles(TextDocument tdoc)
    {
    OdfOfficeStyles stls = tdoc.getOrCreateDocumentStyles();
    OdfStyle ostyle = stls.newStyle(SUBSCRIPT, OdfStyleFamily.Text);
    OdfStylePropertiesBase styleProp =
ostyle.getOrCreatePropertiesElement(OdfStylePropertiesSet.TextProperties);

styleProp.setOdfAttributeValue(OdfTextProperties.TextPosition.getName(),
"sub 58%");

    ostyle = stls.newStyle(SUPERSCRIPT, OdfStyleFamily.Text);
    styleProp =
ostyle.getOrCreatePropertiesElement(OdfStylePropertiesSet.TextProperties);

styleProp.setOdfAttributeValue(OdfTextProperties.TextPosition.getName(),
"super 58%");
    }

- second I created a Paragraph selected some text and set the style to
"superscript":

 Javacode:
        Section s1 = s1 = target.appendSection("S1");
        Paragraph p1 = s1.addParagraph("This is subscripted. This is
superscripted. ");

        TextSelection tsel;
        Span tselSpan1;

        tsel = TextSelection.newTextSelection(null, "sub",
p1.getOdfElement(), 8);
        tselSpan1 = Span.getInstanceof(tsel.createSpanElement());

tselSpan1.getStyleHandler().getStyleElementForWrite().setStyleNameAttribute(SUBSCRIPT);

        tsel = TextSelection.newTextSelection(null, "super",
p1.getOdfElement(), 29);
        tselSpan1 = Span.getInstanceof(tsel.createSpanElement());

tselSpan1.getStyleHandler().getStyleElementForWrite().setStyleNameAttribute(SUPERSCRIPT);




- My generated od-Document does not display super- and subscripted
characters:

I unzipped the document and saw in styles.xml the global styles:

in styles.xml the my global styles are existent:

    </office:styles>

        ......
        <style:style style:family="text" style:name="subscript">
            <style:text-properties style:text-position="sub 58%"/>
        </style:style>
        <style:style style:family="text" style:name="superscript">
            <style:text-properties style:text-position="super 58%"/>
        </style:style>
    </office:styles>


I examined the content.xml:
In content.xml these my global styles are written empty once more:

    <office:automatic-styles>

        .......
        <style:style style:family="text" style:name="subscript"/>
        <style:style style:family="text" style:name="superscript"/>
    </office:automatic-styles>


And the generated textspans reference 'wrong'  text-style-names:

<text:section text:display="true" text:name="S1" text:style-name="a2921cb">
                <text:p>This is <text:span
text:style-name="af1df46">sub</text:span>scripted. This is <text:span
text:style-name="a4007fe">super</text:span>scripted. </text:p>
</text:section>


When I remove the generated empty styles in content.xml and correct the
references of the text:span- styles. the characters are displayed in sub-
and superscript.

What do I wrong in the Javacode?

Thanks in advance

Gio

Reply via email to