import org.apache.poi.hwpf.model.Colorref;
import org.apache.poi.hwpf.model.Hyphenation;
+import org.apache.poi.hwpf.model.StyleSheet;
import org.apache.poi.hwpf.usermodel.BorderCode;
import org.apache.poi.hwpf.usermodel.CharacterProperties;
import org.apache.poi.hwpf.usermodel.DateAndTime;
{
}
- public static CharacterProperties uncompressCHP(CharacterProperties parent,
- byte[] grpprl,
- int offset)
- {
- CharacterProperties newProperties = null;
- try
+ @Deprecated
+ public static CharacterProperties uncompressCHP(
+ CharacterProperties parent, byte[] grpprl, int offset )
{
- newProperties = (CharacterProperties) parent.clone();
+ CharacterProperties newProperties = parent.clone();
+ applySprms( parent, grpprl, offset, true, newProperties );
+ return newProperties;
}
- catch (CloneNotSupportedException cnse)
+
+ public static CharacterProperties uncompressCHP( StyleSheet styleSheet,
+ CharacterProperties parStyle, byte[] grpprl, int offset )
{
- throw new RuntimeException("There is no way this exception should happen!!");
+ CharacterProperties newProperties;
+ if ( parStyle == null )
+ {
+ parStyle = new CharacterProperties();
+ newProperties = new CharacterProperties();
+ }
+ else
+ {
+ newProperties = parStyle.clone();
+ }
+
+ /*
+ * not fully conform to specification, but the fastest way to make it
+ * work. Shall be rewritten if any errors would be found -- vlsergey
+ */
+ Integer style = getIstd( grpprl, offset );
+ if ( style != null )
+ {
+ applySprms( parStyle, styleSheet.getCHPX( style ), 0, false,
+ newProperties );
+ }
+
+ CharacterProperties styleProperties = newProperties;
+ newProperties = styleProperties.clone();
+
+ applySprms( styleProperties, grpprl, offset, true, newProperties );
+ return newProperties;
}
- SprmIterator sprmIt = new SprmIterator(grpprl, offset);
- while (sprmIt.hasNext())
+ private static void applySprms( CharacterProperties parentProperties,
+ byte[] grpprl, int offset, boolean warnAboutNonChpSprms,
+ CharacterProperties targetProperties )
{
- SprmOperation sprm = sprmIt.next();
+ SprmIterator sprmIt = new SprmIterator( grpprl, offset );
+
+ while ( sprmIt.hasNext() )
+ {
+ SprmOperation sprm = sprmIt.next();
- if (sprm.getType() != 2) {
- logger.log( POILogger.WARN, "Non-CHP SPRM returned by SprmIterator: " + sprm );
- continue;
- }
+ if ( sprm.getType() != 2 )
+ {
+ if ( warnAboutNonChpSprms )
+ {
+ logger.log( POILogger.WARN,
+ "Non-CHP SPRM returned by SprmIterator: " + sprm );
+ }
+ continue;
+ }
- unCompressCHPOperation(parent, newProperties, sprm);
+ unCompressCHPOperation( parentProperties, targetProperties, sprm );
+ }
}
- return newProperties;
- }
+ private static Integer getIstd( byte[] grpprl, int offset )
+ {
+ Integer style = null;
+ {
+ SprmIterator sprmIt = new SprmIterator( grpprl, offset );
+ while ( sprmIt.hasNext() )
+ {
+ SprmOperation sprm = sprmIt.next();
+
+ if ( sprm.getType() == 2 && sprm.getOperation() == 0x30 )
+ {
+ // sprmCIstd (0x4A30)
+ style = Integer.valueOf( sprm.getOperand() );
+ }
+ }
+ }
+ return style;
+ }
/**
* Used in decompression of a chpx. This performs an operation defined by
break;
case 0x2f:
break;
- case 0x30:
- newCHP.setIstd (sprm.getOperand());
- break;
+ case 0x30:
+ newCHP.setIstd( sprm.getOperand() );
+ // 0x30 is supported by uncompressCHP(...)
+ break;
case 0x31:
//permutation vector for fast saves, who cares!
newCHP.setKul ((byte) 0);
newCHP.setIco ((byte) 0);
break;
- case 0x33:
- try
- {
- // preserve the fSpec setting from the original CHP
- boolean fSpec = newCHP.isFSpec ();
- newCHP = (CharacterProperties) oldCHP.clone ();
- newCHP.setFSpec (fSpec);
-
- }
- catch (CloneNotSupportedException e)
- {
- //do nothing
- }
- return;
+ case 0x33:
+ // preserve the fSpec setting from the original CHP
+ boolean fSpec = newCHP.isFSpec();
+ newCHP = oldCHP.clone();
+ newCHP.setFSpec( fSpec );
+ return;
case 0x34:
// sprmCKcd
break;
setCv( new Colorref( colour24 & 0xFFFFFF ) );
}
- public Object clone() throws CloneNotSupportedException
+ public CharacterProperties clone()
{
- CharacterProperties cp = (CharacterProperties) super.clone();
-
- cp.setCv( getCv().clone() );
- cp.setDttmRMark( (DateAndTime) getDttmRMark().clone() );
- cp.setDttmRMarkDel( (DateAndTime) getDttmRMarkDel().clone() );
- cp.setDttmPropRMark( (DateAndTime) getDttmPropRMark().clone() );
- cp.setDttmDispFldRMark( (DateAndTime) getDttmDispFldRMark().clone() );
- cp.setXstDispFldRMark( getXstDispFldRMark().clone() );
- cp.setShd( (ShadingDescriptor) getShd().clone() );
- cp.setBrc( (BorderCode) getBrc().clone() );
-
- return cp;
+ try
+ {
+ CharacterProperties cp = (CharacterProperties) super.clone();
+
+ cp.setCv( getCv().clone() );
+ cp.setDttmRMark( (DateAndTime) getDttmRMark().clone() );
+ cp.setDttmRMarkDel( (DateAndTime) getDttmRMarkDel().clone() );
+ cp.setDttmPropRMark( (DateAndTime) getDttmPropRMark().clone() );
+ cp.setDttmDispFldRMark( (DateAndTime) getDttmDispFldRMark().clone() );
+ cp.setXstDispFldRMark( getXstDispFldRMark().clone() );
+ cp.setShd( (ShadingDescriptor) getShd().clone() );
+ cp.setBrc( (BorderCode) getBrc().clone() );
+
+ return cp;
+ }
+ catch ( CloneNotSupportedException exc )
+ {
+ throw new UnsupportedOperationException(
+ "Impossible CloneNotSupportedException occured", exc );
+ }
}
}