From: Nick Burch Date: Sun, 12 Feb 2006 19:01:07 +0000 (+0000) Subject: Start to support friendly usermodel interface to rich text character properties X-Git-Tag: REL_3_0_ALPHA3~181 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c5edf4cb5314f189e99a856b98e6837739ed552f;p=poi.git Start to support friendly usermodel interface to rich text character properties git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@377215 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java index 3b079ec562..8e392d8310 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java @@ -285,9 +285,9 @@ public class TextRun /** * Ensure a StyleTextPropAtom is present for this run, - * by adding if required + * by adding if required. Normally for internal TextRun use. */ - private synchronized void ensureStyleAtomPresent() { + public synchronized void ensureStyleAtomPresent() { if(_styleAtom != null) { // All there return; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java index 4290273b69..b7d2230b55 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java @@ -84,8 +84,8 @@ public class StyleTextPropAtom extends RecordAtom public void setCharacterStyles(LinkedList cs) { charStyles = cs; } /** All the different kinds of paragraph properties we might handle */ - public TextProp[] paragraphTextPropTypes = new TextProp[] { - new BitMaskTextProp(2, 0xF, new String[] { + public static TextProp[] paragraphTextPropTypes = new TextProp[] { + new BitMaskTextProp(2, 0xF, "paragraph_flags", new String[] { "bullet", "bullet.hardfont", "bullet.hardcolor", "bullet.hardsize"} ), @@ -105,7 +105,7 @@ public class StyleTextPropAtom extends RecordAtom new TextProp(2, 0xA0000, "para_unknown_6") }; /** All the different kinds of character properties we might handle */ - public TextProp[] characterTextPropTypes = new TextProp[] { + public static TextProp[] characterTextPropTypes = new TextProp[] { new CharFlagsTextProp(), new TextProp(2, 0x10000, "font.index"), new TextProp(2, 0x20000, "font.size"), @@ -329,6 +329,48 @@ public class StyleTextPropAtom extends RecordAtom public int getCharactersCovered() { return charactersCovered; } /** Fetch the TextProps that define this styling */ public LinkedList getTextPropList() { return textPropList; } + + /** Fetch the TextProp with this name, or null if it isn't present */ + public TextProp findByName(String textPropName) { + for(int i=0; i curProp.getMask()) { + pos++; + } + } + textPropList.add(pos, textProp); + return textProp; + } /** * Create a new collection of text properties (be they paragraph @@ -504,9 +546,10 @@ public class StyleTextPropAtom extends RecordAtom /** Fetch the list of if the sub properties match or not */ public boolean[] getSubPropMatches() { return subPropMatches; } - private BitMaskTextProp(int sizeOfDataBlock, int maskInHeader, String[] subPropNames) { + private BitMaskTextProp(int sizeOfDataBlock, int maskInHeader, String overallName, String[] subPropNames) { super(sizeOfDataBlock,maskInHeader,"bitmask"); this.subPropNames = subPropNames; + this.propName = overallName; subPropMasks = new int[subPropNames.length]; subPropMatches = new boolean[subPropNames.length]; } @@ -545,6 +588,7 @@ public class StyleTextPropAtom extends RecordAtom } else { dataValue -= subPropMasks[idx]; } + subPropMatches[idx] = value; } public Object clone(){ @@ -575,7 +619,7 @@ public class StyleTextPropAtom extends RecordAtom public static final int ENABLE_NUMBERING_2_IDX = 12; private CharFlagsTextProp() { - super(2,0xffff, new String[] { + super(2,0xffff, "char_flags", new String[] { "bold", // 0x0001 "italic", // 0x0002 "underline", // 0x0004 diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java index 1ccfea5d78..ac41821212 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java @@ -20,6 +20,7 @@ package org.apache.poi.hslf.usermodel; import org.apache.poi.hslf.model.TextRun; +import org.apache.poi.hslf.record.StyleTextPropAtom.CharFlagsTextProp; import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection; /** @@ -124,6 +125,39 @@ public class RichTextRun } + // --------------- Internal helpers on rich text properties ------- + private boolean isCharFlagsTextPropVal(int index) { + if(characterStyle == null) { return false; } + + CharFlagsTextProp cftp = (CharFlagsTextProp) + characterStyle.findByName("char_flags"); + + if(cftp == null) { return false; } + return cftp.getSubValue(index); + } + private void setCharFlagsTextPropVal(int index, boolean value) { + if(characterStyle == null) { + parentRun.ensureStyleAtomPresent(); + } + + CharFlagsTextProp cftp = (CharFlagsTextProp) + characterStyle.findByName("char_flags"); + if(cftp == null) { + cftp = (CharFlagsTextProp)characterStyle.addWithName("char_flags"); + } + + cftp.setSubValue(value,index); + } + + // --------------- 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); + } + /** * Internal Use Only - get the underlying paragraph style collection.