mirror of https://github.com/apache/poi.git
fix bug 53182 - Reading combined character styling and direct formatting of a character run
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1405850 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c3f572e2cd
commit
303de7dab6
|
@ -34,6 +34,7 @@
|
|||
|
||||
<changes>
|
||||
<release version="3.9-beta1" date="2012-??-??">
|
||||
<action dev="poi-developers" type="fix">53182 - Reading combined character styling and direct formatting of a character run</action>
|
||||
<action dev="poi-developers" type="fix">52311 - Conversion to html : Problem in titles number </action>
|
||||
<action dev="poi-developers" type="fix">53914 - TableRow#getTopBorder() return bottom's border</action>
|
||||
<action dev="poi-developers" type="fix">53282 - Avoid exception when parsing OPC relationships with non-breaking spaces</action>
|
||||
|
|
|
@ -72,11 +72,8 @@ public final class CHPX extends BytePropertyNode<CHPX>
|
|||
}
|
||||
|
||||
CharacterProperties baseStyle = ss.getCharacterStyle( istd );
|
||||
if (baseStyle == null)
|
||||
baseStyle = new CharacterProperties();
|
||||
|
||||
CharacterProperties props = CharacterSprmUncompressor.uncompressCHP(
|
||||
baseStyle, getGrpprl(), 0 );
|
||||
ss, baseStyle, getGrpprl(), 0 );
|
||||
return props;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.apache.poi.hwpf.usermodel.ShadingDescriptor80;
|
|||
|
||||
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;
|
||||
|
@ -40,35 +41,89 @@ public final class CharacterSprmUncompressor extends SprmUncompressor
|
|||
{
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
catch (CloneNotSupportedException cnse)
|
||||
{
|
||||
throw new RuntimeException("There is no way this exception should happen!!");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
unCompressCHPOperation(parent, newProperties, sprm);
|
||||
CharacterProperties newProperties = parent.clone();
|
||||
applySprms( parent, grpprl, offset, true, newProperties );
|
||||
return newProperties;
|
||||
}
|
||||
|
||||
return newProperties;
|
||||
}
|
||||
public static CharacterProperties uncompressCHP( StyleSheet styleSheet,
|
||||
CharacterProperties parStyle, byte[] grpprl, int offset )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
private static void applySprms( CharacterProperties parentProperties,
|
||||
byte[] grpprl, int offset, boolean warnAboutNonChpSprms,
|
||||
CharacterProperties targetProperties )
|
||||
{
|
||||
SprmIterator sprmIt = new SprmIterator( grpprl, offset );
|
||||
|
||||
while ( sprmIt.hasNext() )
|
||||
{
|
||||
SprmOperation sprm = sprmIt.next();
|
||||
|
||||
if ( sprm.getType() != 2 )
|
||||
{
|
||||
if ( warnAboutNonChpSprms )
|
||||
{
|
||||
logger.log( POILogger.WARN,
|
||||
"Non-CHP SPRM returned by SprmIterator: " + sprm );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
unCompressCHPOperation( parentProperties, targetProperties, sprm );
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -238,9 +293,10 @@ public final class CharacterSprmUncompressor extends SprmUncompressor
|
|||
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!
|
||||
|
@ -257,20 +313,12 @@ public final class CharacterSprmUncompressor extends SprmUncompressor
|
|||
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;
|
||||
|
|
|
@ -370,19 +370,27 @@ public final class CharacterProperties
|
|||
setCv( new Colorref( colour24 & 0xFFFFFF ) );
|
||||
}
|
||||
|
||||
public Object clone() throws CloneNotSupportedException
|
||||
public CharacterProperties clone()
|
||||
{
|
||||
CharacterProperties cp = (CharacterProperties) super.clone();
|
||||
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() );
|
||||
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;
|
||||
return cp;
|
||||
}
|
||||
catch ( CloneNotSupportedException exc )
|
||||
{
|
||||
throw new UnsupportedOperationException(
|
||||
"Impossible CloneNotSupportedException occured", exc );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -535,20 +535,18 @@ public final class CharacterRun
|
|||
_props.setIco24(colour24);
|
||||
}
|
||||
|
||||
/**
|
||||
* clone the CharacterProperties object associated with this
|
||||
* characterRun so that you can apply it to another CharacterRun
|
||||
*
|
||||
* @deprecated This method shall not be public and should not be called from high-level code
|
||||
*/
|
||||
@Deprecated
|
||||
public CharacterProperties cloneProperties() {
|
||||
try {
|
||||
return (CharacterProperties)_props.clone();
|
||||
} catch(java.lang.CloneNotSupportedException e) {
|
||||
throw new RuntimeException(e);
|
||||
/**
|
||||
* clone the CharacterProperties object associated with this characterRun so
|
||||
* that you can apply it to another CharacterRun
|
||||
*
|
||||
* @deprecated This method shall not be public and should not be called from
|
||||
* high-level code
|
||||
*/
|
||||
@Deprecated
|
||||
public CharacterProperties cloneProperties()
|
||||
{
|
||||
return _props.clone();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to create a deep copy of this object.
|
||||
|
|
|
@ -141,6 +141,12 @@ public class TestWordToHtmlConverter extends TestCase
|
|||
getHtmlText( "Bug48075.doc" );
|
||||
}
|
||||
|
||||
public void testBug53182() throws Exception
|
||||
{
|
||||
String result = getHtmlText( "Bug53182.doc" );
|
||||
assertFalse( result.contains( "italic" ) );
|
||||
}
|
||||
|
||||
public void testDocumentProperties() throws Exception
|
||||
{
|
||||
String result = getHtmlText( "documentProperties.doc" );
|
||||
|
@ -183,7 +189,7 @@ public class TestWordToHtmlConverter extends TestCase
|
|||
|
||||
assertContains( result, "<span>Before text; </span><a " );
|
||||
assertContains( result,
|
||||
"<a href=\"http://testuri.org/\"><span>Hyperlink text</span></a>" );
|
||||
"<a href=\"http://testuri.org/\"><span class=\"s1\">Hyperlink text</span></a>" );
|
||||
assertContains( result, "</a><span>; after text</span>" );
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue