CTRst buildCTRst(String text, TreeMap<Integer, CTRPrElt> formats){
if(text.length() != formats.lastKey()) {
throw new IllegalArgumentException("Text length was " + text.length() +
" but the last format index was " + formats.lastKey());
}
CTRst st = CTRst.Factory.newInstance();
int runStartIdx = 0;
for (Iterator<Integer> it = formats.keySet().iterator(); it.hasNext();) {
int runEndIdx = it.next();
CTRElt run = st.addNewR();
String fragment = text.substring(runStartIdx, runEndIdx);
run.setT(fragment);
preserveSpaces(run.xgetT());
CTRPrElt fmt = formats.get(runEndIdx);
if(fmt != null) run.setRPr(fmt);