Kaydet (Commit) e1e4bf8e authored tarafından Philipp Lohmann [pl]'s avatar Philipp Lohmann [pl]

pdfextfix04: #i90800# fix RTL import, use mirror string service, use character…

pdfextfix04: #i90800# fix RTL import, use mirror string service, use character classification instead of overly broad script type complex
üst 5ced7816
...@@ -53,7 +53,7 @@ namespace pdfi ...@@ -53,7 +53,7 @@ namespace pdfi
virtual boost::shared_ptr<ElementTreeVisitor> createStyleCollectingVisitor( virtual boost::shared_ptr<ElementTreeVisitor> createStyleCollectingVisitor(
StyleContainer&, PDFIProcessor&) const = 0; StyleContainer&, PDFIProcessor&) const = 0;
/// Create visitor that emits tree to an output target /// Create visitor that emits tree to an output target
virtual boost::shared_ptr<ElementTreeVisitor> createEmittingVisitor(EmitContext&) const = 0; virtual boost::shared_ptr<ElementTreeVisitor> createEmittingVisitor(EmitContext&, PDFIProcessor&) const = 0;
}; };
typedef boost::shared_ptr<TreeVisitorFactory> TreeVisitorFactorySharedPtr; typedef boost::shared_ptr<TreeVisitorFactory> TreeVisitorFactorySharedPtr;
......
...@@ -36,13 +36,15 @@ ...@@ -36,13 +36,15 @@
#include "drawtreevisiting.hxx" #include "drawtreevisiting.hxx"
#include "genericelements.hxx" #include "genericelements.hxx"
#include <basegfx/polygon/b2dpolypolygontools.hxx> #include "basegfx/polygon/b2dpolypolygontools.hxx"
#include <basegfx/range/b2drange.hxx> #include "basegfx/range/b2drange.hxx"
#include <com/sun/star/i18n/XBreakIterator.hpp> #include "com/sun/star/i18n/XBreakIterator.hpp"
#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include "com/sun/star/lang/XMultiServiceFactory.hpp"
#include "comphelper/processfactory.hxx" #include "comphelper/processfactory.hxx"
#include <com/sun/star/i18n/ScriptType.hpp> #include "com/sun/star/i18n/ScriptType.hpp"
#include "com/sun/star/i18n/DirectionProperty.hpp"
#include <string.h> #include <string.h>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -79,6 +81,18 @@ const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > ...@@ -79,6 +81,18 @@ const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >
return mxBreakIter; return mxBreakIter;
} }
const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification >& DrawXmlEmitter::GetCharacterClassification()
{
if ( !mxCharClass.is() )
{
Reference< XComponentContext > xContext( m_rEmitContext.m_xContext, uno::UNO_SET_THROW );
Reference< XMultiComponentFactory > xMSF( xContext->getServiceManager(), uno::UNO_SET_THROW );
Reference < XInterface > xInterface = xMSF->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.i18n.CharacterClassification"), xContext);
mxCharClass = uno::Reference< i18n::XCharacterClassification >( xInterface, uno::UNO_QUERY );
}
return mxCharClass;
}
void DrawXmlEmitter::visit( HyperlinkElement& elem, const std::list< Element* >::const_iterator& ) void DrawXmlEmitter::visit( HyperlinkElement& elem, const std::list< Element* >::const_iterator& )
{ {
if( elem.Children.empty() ) if( elem.Children.empty() )
...@@ -119,30 +133,25 @@ void DrawXmlEmitter::visit( TextElement& elem, const std::list< Element* >::cons ...@@ -119,30 +133,25 @@ void DrawXmlEmitter::visit( TextElement& elem, const std::list< Element* >::cons
rtl::OUString str(elem.Text.getStr()); rtl::OUString str(elem.Text.getStr());
// Check for CTL // Check for RTL
bool isComplex = false; bool isRTL = false;
for(int i=0; i< elem.Text.getLength(); i++) Reference< i18n::XCharacterClassification > xCC( GetCharacterClassification() );
{ if( xCC.is() )
sal_Int16 nType = GetBreakIterator()->getScriptType( str, i + 1);
if (nType == ::com::sun::star::i18n::ScriptType::COMPLEX)
isComplex = true;
}
#if 0
// FIXME: need to have a service to do this mirroring
if (isComplex) // If so, reverse string
{ {
rtl::OUString flippedStr(RTL_CONSTASCII_USTRINGPARAM( "" )); for(int i=1; i< elem.Text.getLength(); i++)
for(int i = str.getLength() - 1; i >= 0; i--)
{ {
sal_Unicode cChar = str[ i ]; sal_Int16 nType = xCC->getCharacterDirection( str, i );
cChar = static_cast<sal_Unicode>(GetMirroredChar( cChar )); if ( nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT ||
rtl::OUString uC(cChar); nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT_ARABIC ||
flippedStr += uC; nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT_EMBEDDING ||
nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT_OVERRIDE
)
isRTL = true;
} }
str = flippedStr;
} }
#endif
if (isRTL) // If so, reverse string
str = m_rProcessor.mirrorString( str );
m_rEmitContext.rEmitter.beginTag( "text:span", aProps ); m_rEmitContext.rEmitter.beginTag( "text:span", aProps );
......
...@@ -29,9 +29,11 @@ ...@@ -29,9 +29,11 @@
#define INCLUDED_PDFI_DRAWTREEVISITING_HXX #define INCLUDED_PDFI_DRAWTREEVISITING_HXX
#include "treevisiting.hxx" #include "treevisiting.hxx"
#include <com/sun/star/i18n/XBreakIterator.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include "com/sun/star/i18n/XBreakIterator.hpp"
#include <com/sun/star/uno/XComponentContext.hpp> #include "com/sun/star/i18n/XCharacterClassification.hpp"
#include "com/sun/star/lang/XMultiServiceFactory.hpp"
#include "com/sun/star/uno/XComponentContext.hpp"
namespace pdfi namespace pdfi
{ {
...@@ -89,6 +91,9 @@ namespace pdfi ...@@ -89,6 +91,9 @@ namespace pdfi
::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory; ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory;
::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xCtx; ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xCtx;
::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > mxBreakIter; ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > mxBreakIter;
::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification > mxCharClass;
PDFIProcessor& m_rProcessor;
EmitContext& m_rEmitContext ; EmitContext& m_rEmitContext ;
/// writes Impress doc when false /// writes Impress doc when false
...@@ -100,8 +105,10 @@ namespace pdfi ...@@ -100,8 +105,10 @@ namespace pdfi
public: public:
const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >& GetBreakIterator(); const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >& GetBreakIterator();
const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification >& GetCharacterClassification();
enum DocType{ DRAW_DOC, IMPRESS_DOC }; enum DocType{ DRAW_DOC, IMPRESS_DOC };
explicit DrawXmlEmitter(EmitContext& rEmitContext, DocType eDocType) : explicit DrawXmlEmitter(EmitContext& rEmitContext, DocType eDocType, PDFIProcessor& rProc ) :
m_rProcessor( rProc ),
m_rEmitContext(rEmitContext), m_rEmitContext(rEmitContext),
m_bWriteDrawDocument(eDocType==DRAW_DOC) m_bWriteDrawDocument(eDocType==DRAW_DOC)
{} {}
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#ifndef INCLUDED_PDFI_PROCESSOR_HXX #ifndef INCLUDED_PDFI_PROCESSOR_HXX
#define INCLUDED_PDFI_PROCESSOR_HXX #define INCLUDED_PDFI_PROCESSOR_HXX
#include <com/sun/star/util/XStringMapping.hpp>
#include <com/sun/star/xml/sax/XDocumentHandler.hpp> #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
#include <com/sun/star/task/XStatusIndicator.hpp> #include <com/sun/star/task/XStatusIndicator.hpp>
#include <com/sun/star/rendering/XVolatileBitmap.hpp> #include <com/sun/star/rendering/XVolatileBitmap.hpp>
...@@ -108,7 +109,10 @@ namespace pdfi ...@@ -108,7 +109,10 @@ namespace pdfi
void sortElements( Element* pElement, bool bDeep = false ); void sortElements( Element* pElement, bool bDeep = false );
void sortDocument( bool bDeep = false ); void sortDocument( bool bDeep = false );
rtl::OUString mirrorString( const rtl::OUString& i_rInString );
private: private:
void prepareMirrorMap();
void processGlyphLine(); void processGlyphLine();
void processGlyph( double fPreAvarageSpaceValue, void processGlyph( double fPreAvarageSpaceValue,
CharGlyph& rGlyph, CharGlyph& rGlyph,
...@@ -242,6 +246,11 @@ namespace pdfi ...@@ -242,6 +246,11 @@ namespace pdfi
m_xStatusIndicator; m_xStatusIndicator;
bool m_bHaveTextOnDocLevel; bool m_bHaveTextOnDocLevel;
std::vector< sal_Unicode > m_aMirrorMap;
com::sun::star::uno::Reference<
com::sun::star::util::XStringMapping >
m_xMirrorMapper;
bool m_bMirrorMapperTried;
}; };
class CharGlyph class CharGlyph
{ {
......
...@@ -50,7 +50,7 @@ namespace pdfi ...@@ -50,7 +50,7 @@ namespace pdfi
return boost::shared_ptr<ElementTreeVisitor>(new WriterXmlFinalizer(rStyles,rProc)); return boost::shared_ptr<ElementTreeVisitor>(new WriterXmlFinalizer(rStyles,rProc));
} }
virtual boost::shared_ptr<ElementTreeVisitor> createEmittingVisitor(EmitContext& rEmitContext) const virtual boost::shared_ptr<ElementTreeVisitor> createEmittingVisitor(EmitContext& rEmitContext, PDFIProcessor&) const
{ {
return boost::shared_ptr<ElementTreeVisitor>(new WriterXmlEmitter(rEmitContext)); return boost::shared_ptr<ElementTreeVisitor>(new WriterXmlEmitter(rEmitContext));
} }
...@@ -72,10 +72,12 @@ namespace pdfi ...@@ -72,10 +72,12 @@ namespace pdfi
return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlFinalizer(rStyles,rProc)); return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlFinalizer(rStyles,rProc));
} }
virtual boost::shared_ptr<ElementTreeVisitor> createEmittingVisitor(EmitContext& rEmitContext) const virtual boost::shared_ptr<ElementTreeVisitor> createEmittingVisitor(EmitContext& rEmitContext, PDFIProcessor& rProc) const
{ {
return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlEmitter(rEmitContext, return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlEmitter(rEmitContext,
DrawXmlEmitter::IMPRESS_DOC)); DrawXmlEmitter::IMPRESS_DOC,
rProc
));
} }
}; };
...@@ -95,10 +97,12 @@ namespace pdfi ...@@ -95,10 +97,12 @@ namespace pdfi
return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlFinalizer(rStyles,rProc)); return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlFinalizer(rStyles,rProc));
} }
virtual boost::shared_ptr<ElementTreeVisitor> createEmittingVisitor(EmitContext& rEmitContext) const virtual boost::shared_ptr<ElementTreeVisitor> createEmittingVisitor(EmitContext& rEmitContext, PDFIProcessor& rProc) const
{ {
return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlEmitter(rEmitContext, return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlEmitter(rEmitContext,
DrawXmlEmitter::DRAW_DOC)); DrawXmlEmitter::DRAW_DOC,
rProc
));
} }
}; };
......
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