Kaydet (Commit) b156d957 authored tarafından Daniel Rentz [dr]'s avatar Daniel Rentz [dr]

dr78: #i96587# import text formatting from OOXML and BIFF12

üst c15fb917
......@@ -74,7 +74,7 @@ public:
/** Converts the portion and appends it to the passed XText. */
void convert(
const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
sal_Int32 nXfId );
sal_Int32 nXfId, bool bReplaceOld = false );
private:
::rtl::OUString maText; /// Portion text.
......@@ -254,13 +254,10 @@ public:
/** Final processing after import of all strings. */
void finalizeImport();
/** Returns the plain text concatenated from all string portions. */
::rtl::OUString getPlainText() const;
/** Converts the string and writes it into the passed XText. */
void convert(
const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
sal_Int32 nXfId ) const;
sal_Int32 nXfId, bool bReplaceOld = false ) const;
private:
/** Creates, appends, and returns a new empty string portion. */
......
......@@ -48,6 +48,7 @@ using ::com::sun::star::sheet::XSheetAnnotationAnchor;
using ::com::sun::star::sheet::XSheetAnnotationShapeSupplier;
using ::com::sun::star::sheet::XSheetAnnotations;
using ::com::sun::star::sheet::XSheetAnnotationsSupplier;
using ::com::sun::star::text::XText;
namespace oox {
namespace xls {
......@@ -96,30 +97,29 @@ void Comment::finalizeImport()
CellAddress aNotePos( maModel.maRange.Sheet, maModel.maRange.StartColumn, maModel.maRange.StartRow );
if( getAddressConverter().checkCellAddress( aNotePos, true ) && maModel.mxText.get() ) try
{
maModel.mxText->finalizeImport();
OUString aNoteText = maModel.mxText->getPlainText();
// non-empty string required by note implementation
if( aNoteText.getLength() > 0 )
Reference< XSheetAnnotationsSupplier > xAnnosSupp( getSheet(), UNO_QUERY_THROW );
Reference< XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), UNO_SET_THROW );
// non-empty string required by note implementation (real text will be added below)
xAnnos->insertNew( aNotePos, OUString( sal_Unicode( ' ' ) ) );
// receive craeted note from cell (insertNew does not return the note)
Reference< XSheetAnnotationAnchor > xAnnoAnchor( getCell( aNotePos ), UNO_QUERY_THROW );
Reference< XSheetAnnotation > xAnno( xAnnoAnchor->getAnnotation(), UNO_SET_THROW );
Reference< XSheetAnnotationShapeSupplier > xAnnoShapeSupp( xAnno, UNO_QUERY_THROW );
Reference< XShape > xAnnoShape( xAnnoShapeSupp->getAnnotationShape(), UNO_SET_THROW );
// convert shape formatting
if( const ::oox::vml::ShapeBase* pNoteShape = getVmlDrawing().getNoteShape( aNotePos ) )
{
Reference< XSheetAnnotationsSupplier > xAnnosSupp( getSheet(), UNO_QUERY_THROW );
Reference< XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), UNO_SET_THROW );
xAnnos->insertNew( aNotePos, aNoteText );
// receive craeted note from cell (insertNew does not return the note)
Reference< XSheetAnnotationAnchor > xAnnoAnchor( getCell( aNotePos ), UNO_QUERY_THROW );
Reference< XSheetAnnotation > xAnno( xAnnoAnchor->getAnnotation(), UNO_SET_THROW );
Reference< XSheetAnnotationShapeSupplier > xAnnoShapeSupp( xAnno, UNO_QUERY_THROW );
Reference< XShape > xAnnoShape( xAnnoShapeSupp->getAnnotationShape(), UNO_SET_THROW );
// convert shape formatting
if( const ::oox::vml::ShapeBase* pNoteShape = getVmlDrawing().getNoteShape( aNotePos ) )
{
// position and formatting
pNoteShape->convertFormatting( xAnnoShape );
// visibility
const ::oox::vml::ShapeModel::ShapeClientDataPtr& rxClientData = pNoteShape->getShapeModel().mxClientData;
bool bVisible = rxClientData.get() && rxClientData->mbVisible;
xAnno->setIsVisible( bVisible );
}
// position and formatting
pNoteShape->convertFormatting( xAnnoShape );
// visibility
const ::oox::vml::ShapeModel::ShapeClientDataPtr& rxClientData = pNoteShape->getShapeModel().mxClientData;
bool bVisible = rxClientData.get() && rxClientData->mbVisible;
xAnno->setIsVisible( bVisible );
}
// insert text and convert text formatting
maModel.mxText->finalizeImport();
Reference< XText > xAnnoText( xAnnoShape, UNO_QUERY_THROW );
maModel.mxText->convert( xAnnoText, -1, true );
}
catch( Exception& )
{
......
......@@ -37,6 +37,7 @@ using ::rtl::OString;
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::text::XText;
using ::com::sun::star::text::XTextRange;
......@@ -84,21 +85,30 @@ void RichStringPortion::finalizeImport()
mxFont = getStyles().getFont( mnFontId );
}
void RichStringPortion::convert( const Reference< XText >& rxText, sal_Int32 nXfId )
void RichStringPortion::convert( const Reference< XText >& rxText, sal_Int32 nXfId, bool bReplaceOld )
{
Reference< XTextRange > xRange = rxText->getEnd();
xRange->setString( maText );
if( mxFont.get() )
{
PropertySet aPropSet( xRange );
mxFont->writeToPropertySet( aPropSet, FONT_PROPTYPE_TEXT );
}
if( const Font* pFont = getStyles().getFontFromCellXf( nXfId ).get() )
Reference< XTextRange > xRange;
if( bReplaceOld )
xRange.set( rxText, UNO_QUERY );
else
xRange = rxText->getEnd();
OSL_ENSURE( xRange.is(), "RichStringPortion::convert - cannot get text range interface" );
if( xRange.is() )
{
if( pFont->needsRichTextFormat() )
xRange->setString( maText );
if( mxFont.get() )
{
PropertySet aPropSet( xRange );
pFont->writeToPropertySet( aPropSet, FONT_PROPTYPE_TEXT );
mxFont->writeToPropertySet( aPropSet, FONT_PROPTYPE_TEXT );
}
if( const Font* pFont = getStyles().getFontFromCellXf( nXfId ).get() )
{
if( pFont->needsRichTextFormat() )
{
PropertySet aPropSet( xRange );
pFont->writeToPropertySet( aPropSet, FONT_PROPTYPE_TEXT );
}
}
}
}
......@@ -489,20 +499,13 @@ void RichString::finalizeImport()
maFontPortions.forEachMem( &RichStringPortion::finalizeImport );
}
OUString RichString::getPlainText() const
{
OUStringBuffer aBuffer;
for( PortionVec::const_iterator aIt = maFontPortions.begin(), aEnd = maFontPortions.end(); aIt != aEnd; ++aIt )
aBuffer.append( (*aIt)->getText() );
return aBuffer.makeStringAndClear();
}
void RichString::convert( const Reference< XText >& rxText, sal_Int32 nXfId ) const
void RichString::convert( const Reference< XText >& rxText, sal_Int32 nXfId, bool bReplaceOld ) const
{
for( PortionVec::const_iterator aIt = maFontPortions.begin(), aEnd = maFontPortions.end(); aIt != aEnd; ++aIt )
{
(*aIt)->convert( rxText, nXfId );
nXfId = -1; // use passed XF identifier for first portion only
(*aIt)->convert( rxText, nXfId, bReplaceOld );
nXfId = -1; // use passed XF identifier for first portion only
bReplaceOld = false; // do not replace first portion text with following portions
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment