vcl/quartz/ctlayout.cxx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
New commits: commit b200f8d73c7ae1561f410ed7857d0c4f7642d051 Author: Tor Lillqvist <t...@collabora.com> Date: Thu Dec 12 00:33:38 2013 +0200 Fix the iOS coloured text problem The eventual text colour is not known yet when LayoutText() is called. So we need to re-do the layout and justification in DrawText() in case we have a text colour. For some reason this is needed only on iOS. On OS X, the original code manages to display coloured text correctly. But then, on iOS a virtual device is used, and who knows what other strange things going on. Some of the scary warnings printed make you a tad unsure everything is working correcly... (Like "SdrPageView::DrawLayer: Creating temporary SdrPageWindow (ObjectContact), this should never be needed (!)") Change-Id: Ide99c163dea0f758a373c8dab9c54681ff57f624 diff --git a/vcl/quartz/ctlayout.cxx b/vcl/quartz/ctlayout.cxx index 56d8696..b1ce5fb 100644 --- a/vcl/quartz/ctlayout.cxx +++ b/vcl/quartz/ctlayout.cxx @@ -64,6 +64,8 @@ private: // mutable members since these details are all lazy initialized mutable double mfCachedWidth; // cached value of resulting typographical width + mutable float mfAdjustedLineLength; + // x-offset relative to layout origin // currently only used in RTL-layouts mutable double mfBaseAdv; @@ -75,6 +77,7 @@ CTLayout::CTLayout( const CoreTextStyle* pTextStyle ) , mpCTLine( NULL ) , mnCharCount( 0 ) , mfCachedWidth( -1 ) +, mfAdjustedLineLength( 0 ) , mfBaseAdv( 0 ) { } @@ -159,6 +162,7 @@ void CTLayout::AdjustLayout( ImplLayoutArgs& rArgs ) CFRelease( mpCTLine ); mpCTLine = pNewCTLine; mfCachedWidth = nPixelWidth; + mfAdjustedLineLength = nPixelWidth - fTrailingSpace; } // When drawing right aligned text, rounding errors in the position returned by @@ -221,7 +225,36 @@ void CTLayout::DrawText( SalGraphics& rGraphics ) const } CGContextSetTextPosition( rAquaGraphics.mrContext, aTextPos.x, aTextPos.y ); +#ifdef MACOSX + // For some reason on OS X the problem with text colour being out of sync + // does not seem to occur. CTLineDraw( mpCTLine, rAquaGraphics.mrContext ); +#else + if( CFDictionaryGetValue( mpTextStyle->GetStyleDict(), kCTFontAttributeName) ) + { + // We did likely not know the correct intended colour of the + // text in LayoutText(), so have to redo layout and justify. + CFStringRef aCFText = CFAttributedStringGetString( mpAttrString ); + CFAttributedStringRef pAttrString = CFAttributedStringCreate( NULL, aCFText, mpTextStyle->GetStyleDict() ); + CTLineRef pCTLine = CTLineCreateWithAttributedString( pAttrString ); + CFRelease( pAttrString ); + if( mfAdjustedLineLength > 0 ) + { + CTLineRef pNewCTLine = CTLineCreateJustifiedLine( pCTLine, 1.0, mfAdjustedLineLength ); + CFRelease( pCTLine ); + pCTLine = pNewCTLine; + } + CTLineDraw( pCTLine, rAquaGraphics.mrContext ); + CFRelease( pCTLine ); + } + else + { + // FIXME: can the colour be wrong also the other way around: + // some leftover wrong colour was used in LayoutText(), but + // then here the style does not actually contain any colour? + CTLineDraw( mpCTLine, rAquaGraphics.mrContext ); + } +#endif #ifndef IOS // request an update of the changed window area if( rAquaGraphics.IsWindowGraphics() ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits