/** * @return The number of formatting runs used. */ public int numFormattingRuns() { return st.sizeOfRArray(); }
/** * Returns the number of characters this format run covers. * * @param index the index of the formatting run * @return the number of characters this format run covers */ public int getLengthOfFormattingRun(int index) { if(st.sizeOfRArray() == 0 || index >= st.sizeOfRArray()) { return -1; } CTRElt r = st.getRArray(index); return r.getT().length(); }
/** * The index within the string to which the specified formatting run applies. * * @param index the index of the formatting run * @return the index within the string. */ public int getIndexOfFormattingRun(int index) { if(st.sizeOfRArray() == 0) return 0; int pos = 0; for(int i = 0; i < st.sizeOfRArray(); i++){ CTRElt r = st.getRArray(i); if(i == index) return pos; pos += r.getT().length(); } return -1; }
/** * Returns the plain string representation. */ public String getString() { if(st.sizeOfRArray() == 0) { return utfDecode(st.getT()); } StringBuilder buf = new StringBuilder(); //noinspection deprecation - for performance reasons! for(CTRElt r : st.getRArray()){ buf.append(r.getT()); } return utfDecode(buf.toString()); }
/** * Gets a copy of the font used in a particular formatting run. * * @param index the index of the formatting run * @return A copy of the font used or null if no formatting is applied to the specified text run. */ public XSSFFont getFontOfFormattingRun(int index) { if(st.sizeOfRArray() == 0 || index >= st.sizeOfRArray()) { return null; } CTRElt r = st.getRArray(index); if(r.getRPr() != null) { XSSFFont fnt = new XSSFFont(toCTFont(r.getRPr())); fnt.setThemesTable(getThemesTable()); return fnt; } return null; }
protected void setStylesTableReference(StylesTable tbl){ styles = tbl; if(st.sizeOfRArray() > 0) { //noinspection deprecation - for performance reasons! for (CTRElt r : st.getRArray()) { CTRPrElt pr = r.getRPr(); if(pr != null && pr.sizeOfRFontArray() > 0){ String fontName = pr.getRFontArray(0).getVal(); if(fontName.startsWith("#")){ int idx = Integer.parseInt(fontName.substring(1)); XSSFFont font = styles.getFontAt(idx); pr.removeRFont(0); setRunAttributes(font.getCTFont(), pr); } } } } }
/** * Applies a font to the specified characters of a string. * * @param startIndex The start index to apply the font to (inclusive) * @param endIndex The end index to apply to font to (exclusive) * @param font The index of the font to use. */ public void applyFont(int startIndex, int endIndex, Font font) { if (startIndex > endIndex) throw new IllegalArgumentException("Start index must be less than end index, but had " + startIndex + " and " + endIndex); if (startIndex < 0 || endIndex > length()) throw new IllegalArgumentException("Start and end index not in range, but had " + startIndex + " and " + endIndex); if (startIndex == endIndex) return; if(st.sizeOfRArray() == 0 && st.isSetT()) { //convert <t>string</t> into a text run: <r><t>string</t></r> st.addNewR().setT(st.getT()); st.unsetT(); } String text = getString(); XSSFFont xssfFont = (XSSFFont)font; TreeMap<Integer, CTRPrElt> formats = getFormatMap(st); CTRPrElt fmt = CTRPrElt.Factory.newInstance(); setRunAttributes(xssfFont.getCTFont(), fmt); applyFont(formats, startIndex, endIndex, fmt); CTRst newSt = buildCTRst(text, formats); st.set(newSt); }
/** * Append new text to this text run and apply the specify font to it * * @param text the text to append * @param font the font to apply to the appended text or <code>null</code> if no formatting is required */ public void append(String text, XSSFFont font){ if(st.sizeOfRArray() == 0 && st.isSetT()) { //convert <t>string</t> into a text run: <r><t>string</t></r> CTRElt lt = st.addNewR(); lt.setT(st.getT()); preserveSpaces(lt.xgetT()); st.unsetT(); } CTRElt lt = st.addNewR(); lt.setT(text); preserveSpaces(lt.xgetT()); if (font != null) { CTRPrElt pr = lt.addNewRPr(); setRunAttributes(font.getCTFont(), pr); } }
for (int i = 0; i < str.getCTRst().sizeOfRArray(); i++) { CTRElt lt = str.getCTRst().getRArray(i); CTRPrElt ltPr = lt.getRPr();
for (int i = 0; i < str.getCTRst().sizeOfRArray(); i++) { CTRElt lt = str.getCTRst().getRArray(i); CTRPrElt ltPr = lt.getRPr();
/** * @return The number of formatting runs used. */ public int numFormattingRuns() { return st.sizeOfRArray(); }
/** * @return The number of formatting runs used. */ public int numFormattingRuns() { return st.sizeOfRArray(); }
/** * Returns the number of characters this format run covers. * * @param index the index of the formatting run * @return the number of characters this format run covers */ public int getLengthOfFormattingRun(int index) { if(st.sizeOfRArray() == 0 || index >= st.sizeOfRArray()) { return -1; } CTRElt r = st.getRArray(index); return r.getT().length(); }
/** * The index within the string to which the specified formatting run applies. * * @param index the index of the formatting run * @return the index within the string. */ public int getIndexOfFormattingRun(int index) { if(st.sizeOfRArray() == 0) return 0; int pos = 0; for(int i = 0; i < st.sizeOfRArray(); i++){ CTRElt r = st.getRArray(i); if(i == index) return pos; pos += r.getT().length(); } return -1; }
/** * The index within the string to which the specified formatting run applies. * * @param index the index of the formatting run * @return the index within the string. */ public int getIndexOfFormattingRun(int index) { if(st.sizeOfRArray() == 0) return 0; int pos = 0; for(int i = 0; i < st.sizeOfRArray(); i++){ CTRElt r = st.getRArray(i); if(i == index) return pos; pos += r.getT().length(); } return -1; }
/** * Returns the number of characters this format run covers. * * @param index the index of the formatting run * @return the number of characters this format run covers */ public int getLengthOfFormattingRun(int index) { if(st.sizeOfRArray() == 0) return length(); for(int i = 0; i < st.sizeOfRArray(); i++){ CTRElt r = st.getRArray(i); if(i == index) return r.getT().length(); } return -1; }
/** * Returns the plain string representation. */ public String getString() { if(st.sizeOfRArray() == 0) { return utfDecode(st.getT()); } StringBuilder buf = new StringBuilder(); //noinspection deprecation - for performance reasons! for(CTRElt r : st.getRArray()){ buf.append(r.getT()); } return utfDecode(buf.toString()); }
/** * Returns the plain string representation. */ @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support public String getString() { if(st.sizeOfRArray() == 0) { return utfDecode(st.getT()); } StringBuffer buf = new StringBuffer(); for(CTRElt r : st.getRArray()){ buf.append(r.getT()); } return utfDecode(buf.toString()); }
/** * Gets a copy of the font used in a particular formatting run. * * @param index the index of the formatting run * @return A copy of the font used or null if no formatting is applied to the specified text run. */ public XSSFFont getFontOfFormattingRun(int index) { if(st.sizeOfRArray() == 0) return null; for(int i = 0; i < st.sizeOfRArray(); i++){ CTRElt r = st.getRArray(i); if(i == index) { XSSFFont fnt = new XSSFFont(toCTFont(r.getRPr())); fnt.setThemesTable(getThemesTable()); return fnt; } } return null; }
/** * Append new text to this text run and apply the specify font to it * * @param text the text to append * @param font the font to apply to the appended text or <code>null</code> if no formatting is required */ public void append(String text, XSSFFont font){ if(st.sizeOfRArray() == 0 && st.isSetT()) { //convert <t>string</t> into a text run: <r><t>string</t></r> CTRElt lt = st.addNewR(); lt.setT(st.getT()); preserveSpaces(lt.xgetT()); st.unsetT(); } CTRElt lt = st.addNewR(); lt.setT(text); preserveSpaces(lt.xgetT()); CTRPrElt pr = lt.addNewRPr(); if(font != null) setRunAttributes(font.getCTFont(), pr); }