aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2008-11-06 10:49:51 +0000
committerYegor Kozlov <yegor@apache.org>2008-11-06 10:49:51 +0000
commit886e06cb2ac60fd9ecd45b43e3796dda2951b707 (patch)
treec967dc66475bfda5635182f521229b075e092b96 /src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
parent2963774c3752202c0686b0223d7dfd8ae1973ca8 (diff)
downloadpoi-886e06cb2ac60fd9ecd45b43e3796dda2951b707.tar.gz
poi-886e06cb2ac60fd9ecd45b43e3796dda2951b707.zip
1. included ooxml javadocs in build.xml2. added a new rich example: BusinessPlan.java3. misc bug fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@711839 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java85
1 files changed, 39 insertions, 46 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
index 71529e9f46..54d5938f48 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
@@ -68,7 +68,6 @@ import java.util.ArrayList;
public class XSSFRichTextString implements RichTextString {
private CTRst st;
private StylesTable styles;
- private ArrayList<CTRPrElt> fontIdRuns;
/**
* Create a rich text string and initialize it with empty string
@@ -106,7 +105,6 @@ public class XSSFRichTextString implements RichTextString {
//when setStylesTableReference is called
font = new XSSFFont();
font.setFontName("#" + fontIndex);
- fontIdRuns = new ArrayList<CTRPrElt>();
} else {
font = styles.getFontAt(fontIndex);
}
@@ -139,50 +137,50 @@ public class XSSFRichTextString implements RichTextString {
XSSFFont xssfFont = (XSSFFont)font;
ArrayList<CTRElt> runs = new ArrayList<CTRElt>();
+ CTRElt[] r = st.getRArray();
int pos = 0;
- int i;
- for (i = 0; i < st.sizeOfRArray(); i++) {
- CTRElt r = st.getRArray(i);
-
- int len = r.getT().length();
- int p1 = pos;
- int p2 = pos + len;
- if(startIndex > p2) {
- runs.add(r);
- } else if (startIndex >= p1 && startIndex < p2){
- String t = r.getT();
- r.setT(t.substring(0, startIndex-p1));
- runs.add(r);
+ for (int i = 0; i < r.length; i++) {
+ int rStart = pos;
+ String t = r[i].getT();
+ int rEnd = rStart + t.length();
+
+ if(rEnd <= startIndex) {
+ runs.add(r[i]);
+ pos += r[i].getT().length();
+ }
+ else if (startIndex > rStart && startIndex < rEnd){
+ CTRElt c = (CTRElt)r[i].copy();
+ String txt = text.substring(rStart, startIndex);
+ c.setT(txt);
+ runs.add(c);
+ pos += txt.length();
} else {
break;
}
- pos = p2;
}
- CTRElt r = CTRElt.Factory.newInstance();
- r.setT(text.substring(startIndex, endIndex));
- CTRPrElt pr = r.addNewRPr();
+ CTRElt rt = CTRElt.Factory.newInstance();
+ String txt = text.substring(startIndex, endIndex);
+ rt.setT(txt);
+ CTRPrElt pr = rt.addNewRPr();
setRunAttributes(xssfFont.getCTFont(), pr);
- if(fontIdRuns != null) fontIdRuns.add(pr);
- runs.add(r);
-
- for (; i < st.sizeOfRArray(); i++) {
- r = st.getRArray(i);
-
- int len = r.getT().length();
- int p1 = pos;
- int p2 = pos + len;
- if(endIndex > p2) {
- ;
- } else if (endIndex >= p1 && endIndex < p2){
- String t = r.getT();
- r.setT(t.substring(endIndex-p1, len));
- runs.add(r);
- } else {
- runs.add(r);
+ runs.add(rt);
+ pos += txt.length();
+
+ for (int i = 0; i < r.length; i++) {
+ int rStart = pos;
+ String t = r[i].getT();
+ int rEnd = Math.min(rStart + t.length(), text.length());
+
+ if (endIndex < rEnd){
+ CTRElt c = (CTRElt)r[i].copy();
+ txt = text.substring(rStart, rEnd);
+ c.setT(txt);
+ runs.add(c);
+ pos += txt.length();
}
- pos = p2;
}
+
st.setRArray(runs.toArray(new CTRElt[runs.size()]));
}
@@ -202,9 +200,6 @@ public class XSSFRichTextString implements RichTextString {
setRunAttributes(((XSSFFont)font).getCTFont(), r.addNewRPr());
st.setRArray(new CTRElt[]{r});
}
-
- if(fontIdRuns != null) fontIdRuns.add(st.getRArray(0).getRPr());
-
}
/**
@@ -217,7 +212,6 @@ public class XSSFRichTextString implements RichTextString {
if(styles == null) {
font = new XSSFFont();
font.setFontName("#" + fontIndex);
- fontIdRuns = new ArrayList<CTRPrElt>();
} else {
font = styles.getFontAt(fontIndex);
}
@@ -240,8 +234,6 @@ public class XSSFRichTextString implements RichTextString {
lt.setT(text);
CTRPrElt pr = lt.addNewRPr();
if(font != null) setRunAttributes(font.getCTFont(), pr);
-
- if(fontIdRuns != null) fontIdRuns.add(pr);
}
/**
@@ -419,9 +411,10 @@ public class XSSFRichTextString implements RichTextString {
protected void setStylesTableReference(StylesTable tbl){
styles = tbl;
- if(fontIdRuns != null){
- for (CTRPrElt pr : fontIdRuns) {
- if(pr.sizeOfRFontArray() > 0 ) {
+ if(st.sizeOfRArray() > 0) {
+ for (CTRElt r : st.getRArray()) {
+ CTRPrElt pr = r.getRPr();
+ if(pr != null){
String fontName = pr.getRFontArray(0).getVal();
if(fontName.startsWith("#")){
int idx = Integer.parseInt(fontName.substring(1));