📄 richtextrun.java
字号:
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(); } /** * 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. */ private int getParaTextPropVal(String propName) { 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(); } /** * 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 */ public void setParaTextPropVal(String propName, int val) { // 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); } /** * 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 */ public void setCharTextPropVal(String propName, int val) { // 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); } // --------------- Friendly getters / setters on rich text properties ------- public boolean isBold() { return isCharFlagsTextPropVal(CharFlagsTextProp.BOLD_IDX); } public void setBold(boolean bold) { setCharFlagsTextPropVal(CharFlagsTextProp.BOLD_IDX, bold); } public boolean isItalic() { return isCharFlagsTextPropVal(CharFlagsTextProp.ITALIC_IDX); } public void setItalic(boolean italic) { setCharFlagsTextPropVal(CharFlagsTextProp.ITALIC_IDX, italic); } public boolean isUnderlined() { return isCharFlagsTextPropVal(CharFlagsTextProp.UNDERLINE_IDX); } public void setUnderlined(boolean underlined) { setCharFlagsTextPropVal(CharFlagsTextProp.UNDERLINE_IDX, underlined); } public int getFontSize() { return getCharTextPropVal("font.size"); } public void setFontSize(int fontSize) { setCharTextPropVal("font.size", fontSize); } public void setFontName(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 String getFontName() { if (slideShow == null) { return _fontname; } else { int fontIdx = getCharTextPropVal("font.index"); if(fontIdx == -1) { return null; } return slideShow.getFontCollection().getFontWithId(fontIdx); } } /** * @return font color as RGB value * @see java.awt.Color */ public Color getFontColor() { 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()); } /** * Sets color of the text, as a int bgr. * (PowerPoint stores as BlueGreenRed, not the more * usual RedGreenBlue) * @see java.awt.Color */ public void setFontColor(int bgr) { setCharTextPropVal("font.color", bgr); } /** * Sets color of the text, as a java.awt.Color */ public void setFontColor(Color color) { // In PowerPont RGB bytes are swapped, as BGR int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB(); setFontColor(rgb); } /** * Sets the type of horizontal alignment for the text. * One of the <code>Align*</code> constants defined in the <code>TextBox</code> class. * * @param align - the type of alignment */ public void setAlignment(int align) { setParaTextPropVal("alignment", align); } /** * Returns the type of horizontal alignment for the text. * One of the <code>Align*</code> constants defined in the <code>TextBox</class> class. * * @return the type of alignment */ public int getAlignment() { return getParaTextPropVal("alignment"); } /** * * @return indentation level */ public int getIndentLevel() { return paragraphStyle == null ? 0 : paragraphStyle.getReservedField(); } /** * Sets whether this rich text run has bullets */ public void setBullet(boolean flag) { setFlag(false, ParagraphFlagsTextProp.BULLET_IDX, flag); } /** * Returns whether this rich text run has bullets */ public boolean isBullet() { return getFlag(false, ParagraphFlagsTextProp.BULLET_IDX); } /** * Sets the bullet character */ public void setBulletChar(char c) { setParaTextPropVal("bullet.char", c); } /** * Returns the bullet character */ public char getBulletChar() { return (char)getParaTextPropVal("bullet.char"); } /** * Sets the bullet offset */ public void setBulletOffset(int offset) { setParaTextPropVal("bullet.offset", offset*Shape.MASTER_DPI/Shape.POINT_DPI); } /** * Returns the bullet offset */ public int getBulletOffset() { return getParaTextPropVal("bullet.offset")*Shape.POINT_DPI/Shape.MASTER_DPI; } /** * Sets the text offset */ public void setTextOffset(int offset) { setParaTextPropVal("text.offset", offset*Shape.MASTER_DPI/Shape.POINT_DPI); } /** * Returns the text offset */ public int getTextOffset() { return getParaTextPropVal("text.offset")*Shape.POINT_DPI/Shape.MASTER_DPI; } // --------------- Internal HSLF methods, not intended for end-user use! ------- /** * Internal Use Only - get the underlying paragraph style collection. * For normal use, use the friendly setters and getters */ public TextPropCollection _getRawParagraphStyle() { return paragraphStyle; } /** * Internal Use Only - get the underlying character style collection. * For normal use, use the friendly setters and getters */ public TextPropCollection _getRawCharacterStyle() { return characterStyle; } /** * Internal Use Only - are the Paragraph styles shared? */ public boolean _isParagraphStyleShared() { return sharingParagraphStyle; } /** * Internal Use Only - are the Character styles shared? */ public boolean _isCharacterStyleShared() { return sharingCharacterStyle; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -