Add support for setting some of the style properties
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353757 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cba94f3955
commit
7d4ea7f10e
@ -25,9 +25,10 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A StyleTextPropAtom (type 4001). Holds character properties (font type,
|
* A StyleTextPropAtom (type 4001). Holds basic character properties
|
||||||
* font size, colour, bold, italic etc) and paragraph properties
|
* (bold, italic, underline, possibly more?) and paragraph properties
|
||||||
* (alignment, line spacing etc) for a block of text
|
* (alignment, line spacing etc) for the block of text (TextBytesAtom
|
||||||
|
* or TextCharsAtom) that this record follows
|
||||||
*
|
*
|
||||||
* @author Nick Burch
|
* @author Nick Burch
|
||||||
*/
|
*/
|
||||||
@ -55,6 +56,15 @@ public class StyleTextPropAtom extends RecordAtom
|
|||||||
return charStyles;
|
return charStyles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the number of characters covered by these text styles.
|
||||||
|
* This must equal the number of characters in the Text record
|
||||||
|
* that precedes this record, or things won't behave properly
|
||||||
|
*/
|
||||||
|
public void setParagraphStyleCharactersCoveredLength(int len) {
|
||||||
|
paraStyleLen = (short)len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* *************** record code follows ********************** */
|
/* *************** record code follows ********************** */
|
||||||
|
|
||||||
@ -110,6 +120,25 @@ public class StyleTextPropAtom extends RecordAtom
|
|||||||
System.arraycopy(source,start+8+10+cpos,reserved,0,reserved.length);
|
System.arraycopy(source,start+8+10+cpos,reserved,0,reserved.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A new set of text style properties for some text without any
|
||||||
|
*/
|
||||||
|
public StyleTextPropAtom() {
|
||||||
|
_header = new byte[8];
|
||||||
|
reserved = new byte[0];
|
||||||
|
charStyles = new CharacterStyle[0];
|
||||||
|
|
||||||
|
// Set our type
|
||||||
|
LittleEndian.putInt(_header,2,(short)_type);
|
||||||
|
// Our initial size is 10
|
||||||
|
LittleEndian.putInt(_header,4,10);
|
||||||
|
|
||||||
|
// Blank paragraph style
|
||||||
|
paraStyleLen = 0;
|
||||||
|
paraStyle1 = 0;
|
||||||
|
paraStyle2 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We are of type 4001
|
* We are of type 4001
|
||||||
*/
|
*/
|
||||||
@ -159,6 +188,13 @@ public class StyleTextPropAtom extends RecordAtom
|
|||||||
private int style2;
|
private int style2;
|
||||||
private short style3;
|
private short style3;
|
||||||
|
|
||||||
|
// style1 0x00010000
|
||||||
|
private static final int BOLD_STYLE = 65536;
|
||||||
|
// style1 0x00020000
|
||||||
|
private static final int ITALIC_STYLE = 131072;
|
||||||
|
// style1 0x00040000
|
||||||
|
private static final int UNDERLINED_STYLE = 262144;
|
||||||
|
|
||||||
/** Create a new Character Style from on-disk data */
|
/** Create a new Character Style from on-disk data */
|
||||||
protected CharacterStyle(short len, int s1, int s2, short s3) {
|
protected CharacterStyle(short len, int s1, int s2, short s3) {
|
||||||
styleLen = len;
|
styleLen = len;
|
||||||
@ -183,30 +219,73 @@ public class StyleTextPropAtom extends RecordAtom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the number of characters covered by these properties */
|
|
||||||
|
/**
|
||||||
|
* Return the number of characters covered by these properties.
|
||||||
|
* If it's the last CharacterStyle of a StyleTextPropAtom, it
|
||||||
|
* will normally be 0, indicating it applies to all the remaining
|
||||||
|
* text.
|
||||||
|
*/
|
||||||
public int getCharactersCoveredLength() {
|
public int getCharactersCoveredLength() {
|
||||||
return styleLen;
|
return styleLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the number of characters covered by these properties.
|
||||||
|
* If this is the last CharacterStyle of a StyleTextPropAtom, then
|
||||||
|
* a value of 0 should be used
|
||||||
|
*/
|
||||||
|
public void setCharactersCoveredLength(int len) {
|
||||||
|
styleLen = (short)len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Checks to see if the text is bold */
|
/** Checks to see if the text is bold */
|
||||||
public boolean isBold() {
|
public boolean isBold() {
|
||||||
// style1 0x00010000
|
if ((style1 & BOLD_STYLE) == BOLD_STYLE) { return true; }
|
||||||
if ((style1 & 65536) == 65536) { return true; }
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks to see if the text is italic */
|
/** Checks to see if the text is italic */
|
||||||
public boolean isItalic() {
|
public boolean isItalic() {
|
||||||
// style1 0x00020000
|
if ((style1 & ITALIC_STYLE) == ITALIC_STYLE) { return true; }
|
||||||
if ((style1 & 131072) == 131072) { return true; }
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks to see if the text is underlined */
|
/** Checks to see if the text is underlined */
|
||||||
public boolean isUnderlined() {
|
public boolean isUnderlined() {
|
||||||
// style1 0x00040000
|
if ((style1 & UNDERLINED_STYLE) == UNDERLINED_STYLE) { return true; }
|
||||||
if ((style1 & 262144) == 262144) { return true; }
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sets the text to be bold/not bold */
|
||||||
|
public void setBold(boolean bold) {
|
||||||
|
if(bold == isBold()) { return; }
|
||||||
|
if(bold) {
|
||||||
|
style1 += BOLD_STYLE;
|
||||||
|
} else {
|
||||||
|
style1 -= BOLD_STYLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the text to be italic/not italic */
|
||||||
|
public void setItalic(boolean italic) {
|
||||||
|
if(italic == isItalic()) { return; }
|
||||||
|
if(italic) {
|
||||||
|
style1 += ITALIC_STYLE;
|
||||||
|
} else {
|
||||||
|
style1 -= ITALIC_STYLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the text to be underlined/not underlined */
|
||||||
|
public void setUnderlined(boolean underlined) {
|
||||||
|
if(underlined == isUnderlined()) { return; }
|
||||||
|
if(underlined) {
|
||||||
|
style1 += UNDERLINED_STYLE;
|
||||||
|
} else {
|
||||||
|
style1 -= UNDERLINED_STYLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user