FileDocCategorySizeDatePackage
RichTextRun.javaAPI DocApache Poi 3.0.115210Thu May 31 18:45:28 BST 2007org.apache.poi.hslf.usermodel

RichTextRun

public class RichTextRun extends Object
Represents a run of text, all with the same style TODO: get access to the font/character properties
author
Nick Burch

Fields Summary
private TextRun
parentRun
The TextRun we belong to
private SlideShow
slideShow
The SlideShow we belong to
private int
startPos
Where in the parent TextRun we start from
private int
length
How long a string (in the parent TextRun) we represent
private String
_fontname
private TextPropCollection
paragraphStyle
Our paragraph and character style. Note - we may share these styles with other RichTextRuns
private TextPropCollection
characterStyle
private boolean
sharingParagraphStyle
private boolean
sharingCharacterStyle
Constructors Summary
public RichTextRun(TextRun parent, int startAt, int len)
Create a new wrapper around a (currently not) rich text string

param
parent
param
startAt
param
len

		this(parent, startAt, len, null, null, false, false);
	
public RichTextRun(TextRun parent, int startAt, int len, TextPropCollection pStyle, TextPropCollection cStyle, boolean pShared, boolean cShared)
Create a new wrapper around a rich text string

param
parent The parent TextRun
param
startAt The start position of this run
param
len The length of this run
param
pStyle The paragraph style property collection
param
cStyle The character style property collection
param
pShared The paragraph styles are shared with other runs
param
cShared The character styles are shared with other runs

		parentRun = parent;
		startPos = startAt;
		length = len;
		paragraphStyle = pStyle;
		characterStyle = cStyle;
		sharingParagraphStyle = pShared;
		sharingCharacterStyle = cShared;
	
Methods Summary
public org.apache.poi.hslf.model.textproperties.TextPropCollection_getRawCharacterStyle()
Internal Use Only - get the underlying character style collection. For normal use, use the friendly setters and getters

 return characterStyle; 
public org.apache.poi.hslf.model.textproperties.TextPropCollection_getRawParagraphStyle()
Internal Use Only - get the underlying paragraph style collection. For normal use, use the friendly setters and getters

 return paragraphStyle; 
public boolean_isCharacterStyleShared()
Internal Use Only - are the Character styles shared?

 return sharingCharacterStyle; 
public boolean_isParagraphStyleShared()
Internal Use Only - are the Paragraph styles shared?

 return sharingParagraphStyle; 
private org.apache.poi.hslf.model.textproperties.TextPropfetchOrAddTextProp(org.apache.poi.hslf.model.textproperties.TextPropCollection textPropCol, java.lang.String textPropName)
Returns the named TextProp, either by fetching it (if it exists) or adding it (if it didn't)

param
textPropCol The TextPropCollection to fetch from / add into
param
textPropName The name of the TextProp to fetch/add

		// Fetch / Add the TextProp
		TextProp tp = textPropCol.findByName(textPropName);
		if(tp == null) {
			tp = textPropCol.addWithName(textPropName);
		}
		return tp;
	
public intgetAlignment()
Returns the type of horizontal alignment for the text. One of the Align* constants defined in the TextBox class.

return
the type of alignment

        return getParaTextPropVal("alignment");
    
public chargetBulletChar()
Returns the bullet character

        return (char)getParaTextPropVal("bullet.char");
    
public intgetBulletOffset()
Returns the bullet offset

        return getParaTextPropVal("bullet.offset")*Shape.POINT_DPI/Shape.MASTER_DPI;
    
private intgetCharTextPropVal(java.lang.String propName)
Fetch the value of the given Character related TextProp. Returns -1 if that TextProp isn't present. If the TextProp isn't present, the value from the appropriate Master Sheet will apply.

        TextProp prop = null;
        if (characterStyle != null){
            prop = characterStyle.findByName(propName);
        }

        if (prop == null){
            Sheet sheet = parentRun.getSheet();
            int txtype = parentRun.getRunType();
            MasterSheet master = sheet.getMasterSheet();
            if (master != null)
                prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, true);
        }
		return prop == null ? -1 : prop.getValue();
	
private booleangetFlag(boolean isCharacter, int index)

        TextPropCollection props;
        String propname;
        if (isCharacter){
            props = characterStyle;
            propname = CharFlagsTextProp.NAME;
        } else {
            props = paragraphStyle;
            propname = ParagraphFlagsTextProp.NAME;
        }

        BitMaskTextProp prop = null;
        if (props != null){
            prop = (BitMaskTextProp)props.findByName(propname);
        }
        if (prop == null){
            Sheet sheet = parentRun.getSheet();
            int txtype = parentRun.getRunType();
            MasterSheet master = sheet.getMasterSheet();
            if (master != null)
                prop = (BitMaskTextProp)master.getStyleAttribute(txtype, getIndentLevel(), propname, isCharacter);
        }

        return prop == null ? false : prop.getSubValue(index);
    
public java.awt.ColorgetFontColor()

return
font color as RGB value
see
java.awt.Color

        int rgb = getCharTextPropVal("font.color");
        if (rgb >= 0x8000000) {
            int idx = rgb % 0x8000000;
            ColorSchemeAtom ca = parentRun.getSheet().getColorScheme();
            if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);
        }

        Color tmp = new Color(rgb, true);
        return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
	
public java.lang.StringgetFontName()

        if (slideShow == null) {
            return _fontname;
        } else {
            int fontIdx = getCharTextPropVal("font.index");
            if(fontIdx == -1) { return null; }
            return slideShow.getFontCollection().getFontWithId(fontIdx);
        }
	
public intgetFontSize()

		return getCharTextPropVal("font.size");
	
public intgetIndentLevel()

return
indentation level

        return paragraphStyle == null ? 0 : paragraphStyle.getReservedField();
    
public intgetLength()
Get the length of the text

		return length;
	
private intgetParaTextPropVal(java.lang.String propName)
Fetch the value of the given Paragraph related TextProp. Returns -1 if that TextProp isn't present. If the TextProp isn't present, the value from the appropriate Master Sheet will apply.

        TextProp prop = null;
        if (paragraphStyle != null){
            prop = paragraphStyle.findByName(propName);
        }
        if (prop == null){
            Sheet sheet = parentRun.getSheet();
            int txtype = parentRun.getRunType();
            MasterSheet master = sheet.getMasterSheet();
            if (master != null)
                prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, false);
        }

		return prop == null ? -1 : prop.getValue();
	
public java.lang.StringgetRawText()
Fetch the text, in raw storage form

		return parentRun.getRawText().substring(startPos, startPos+length);
	
public java.lang.StringgetText()
Fetch the text, in output suitable form

		return parentRun.getText().substring(startPos, startPos+length);
	
public intgetTextOffset()
Returns the text offset

        return getParaTextPropVal("text.offset")*Shape.POINT_DPI/Shape.MASTER_DPI;
    
public booleanisBold()

		return isCharFlagsTextPropVal(CharFlagsTextProp.BOLD_IDX);
	
public booleanisBullet()
Returns whether this rich text run has bullets

        return getFlag(false, ParagraphFlagsTextProp.BULLET_IDX);
    
private booleanisCharFlagsTextPropVal(int index)
Fetch the value of the given flag in the CharFlagsTextProp. Returns false if the CharFlagsTextProp isn't present, since the text property won't be set if there's no CharFlagsTextProp.

		return getFlag(true, index);
	
public booleanisItalic()

		return isCharFlagsTextPropVal(CharFlagsTextProp.ITALIC_IDX);
	
public booleanisUnderlined()

		return isCharFlagsTextPropVal(CharFlagsTextProp.UNDERLINE_IDX);
	
public voidsetAlignment(int align)
Sets the type of horizontal alignment for the text. One of the Align* constants defined in the TextBox class.

param
align - the type of alignment

        setParaTextPropVal("alignment", align);
    
public voidsetBold(boolean bold)

		setCharFlagsTextPropVal(CharFlagsTextProp.BOLD_IDX, bold);
	
public voidsetBullet(boolean flag)
Sets whether this rich text run has bullets

        setFlag(false, ParagraphFlagsTextProp.BULLET_IDX, flag);
    
public voidsetBulletChar(char c)
Sets the bullet character

        setParaTextPropVal("bullet.char", c);
    
public voidsetBulletOffset(int offset)
Sets the bullet offset

        setParaTextPropVal("bullet.offset", offset*Shape.MASTER_DPI/Shape.POINT_DPI);
    
private voidsetCharFlagsTextPropVal(int index, boolean value)
Set the value of the given flag in the CharFlagsTextProp, adding it if required.

        setFlag(true, index, value);
	
private voidsetCharTextPropVal(java.lang.String propName, int val)
Sets the value of the given Paragraph TextProp, add if required

param
propName The name of the Paragraph TextProp
param
val The value to set for the TextProp

		// Ensure we have the StyleTextProp atom we're going to need
		if(characterStyle == null) {
			parentRun.ensureStyleAtomPresent();
			// characterStyle will now be defined
		}
		
		TextProp tp = fetchOrAddTextProp(characterStyle, propName);
		tp.setValue(val);
	
private voidsetFlag(boolean isCharacter, int index, boolean value)

        TextPropCollection props;
        String propname;
        if (isCharacter){
            props = characterStyle;
            propname = CharFlagsTextProp.NAME;
        } else {
            props = paragraphStyle;
            propname = ParagraphFlagsTextProp.NAME;
        }

		// Ensure we have the StyleTextProp atom we're going to need
		if(props == null) {
			parentRun.ensureStyleAtomPresent();
            props = isCharacter ? characterStyle : paragraphStyle;
		}

		BitMaskTextProp prop = (BitMaskTextProp) fetchOrAddTextProp(props, propname);
		prop.setSubValue(value,index);
    
public voidsetFontColor(int bgr)
Sets color of the text, as a int bgr. (PowerPoint stores as BlueGreenRed, not the more usual RedGreenBlue)

see
java.awt.Color

		setCharTextPropVal("font.color", bgr);
	
public voidsetFontColor(java.awt.Color color)
Sets color of the text, as a java.awt.Color

        // In PowerPont RGB bytes are swapped, as BGR
        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB();
        setFontColor(rgb);
    
public voidsetFontName(java.lang.String fontName)

        if (slideShow == null) {
            //we can't set font since slideshow is not assigned yet
            _fontname = fontName;
        } else {
    		// Get the index for this font (adding if needed)
	    	int fontIdx = slideShow.getFontCollection().addFont(fontName);
		    setCharTextPropVal("font.index", fontIdx);
        }
	
public voidsetFontSize(int fontSize)

		setCharTextPropVal("font.size", fontSize);
	
public voidsetItalic(boolean italic)

		setCharFlagsTextPropVal(CharFlagsTextProp.ITALIC_IDX, italic);
	
private voidsetParaTextPropVal(java.lang.String propName, int val)
Sets the value of the given Character TextProp, add if required

param
propName The name of the Character TextProp
param
val The value to set for the TextProp

		// Ensure we have the StyleTextProp atom we're going to need
		if(paragraphStyle == null) {
			parentRun.ensureStyleAtomPresent();
			// paragraphStyle will now be defined
		}
		
		TextProp tp = fetchOrAddTextProp(paragraphStyle, propName);
		tp.setValue(val);
	
public voidsetText(java.lang.String text)
Change the text

		length = text.length();
		parentRun.changeTextInRichTextRun(this,text);
	
public voidsetTextOffset(int offset)
Sets the text offset

        setParaTextPropVal("text.offset", offset*Shape.MASTER_DPI/Shape.POINT_DPI);
    
public voidsetUnderlined(boolean underlined)

		setCharFlagsTextPropVal(CharFlagsTextProp.UNDERLINE_IDX, underlined);
	
public voidsupplySlideShow(org.apache.poi.hslf.usermodel.SlideShow ss)
Supply the SlideShow we belong to

		slideShow = ss;
        if (_fontname != null) {
            setFontName(_fontname);
            _fontname = null;
        }
	
public voidsupplyTextProps(org.apache.poi.hslf.model.textproperties.TextPropCollection pStyle, org.apache.poi.hslf.model.textproperties.TextPropCollection cStyle, boolean pShared, boolean cShared)
Supply (normally default) textprops, and if they're shared, when a run gets them

		if(paragraphStyle != null || characterStyle != null) {
			throw new IllegalStateException("Can't call supplyTextProps if run already has some");
		}
		paragraphStyle = pStyle;
		characterStyle = cStyle;
		sharingParagraphStyle = pShared;
		sharingCharacterStyle = cShared;
	
public voidupdateStartPosition(int startAt)
Tells the RichTextRun its new position in the parent TextRun

param
startAt

		startPos = startAt;