Kaydet (Commit) d9d16df2 authored tarafından Norbert Thiebaud's avatar Norbert Thiebaud

vcl quartz: draw 'bullet' manually for better control

Change-Id: If0f6bd93adc5d39fd421bb482833619f85f7a461
üst 6ca2d0d6
...@@ -78,7 +78,7 @@ public: ...@@ -78,7 +78,7 @@ public:
// positioning related inputs // positioning related inputs
const DeviceCoordinate* mpDXArray; // in pixel units const DeviceCoordinate* mpDXArray; // in pixel units
DeviceCoordinate mnLayoutWidth; // in pixel units DeviceCoordinate mnLayoutWidth; // in pixel units
int mnOrientation; // in 0-3600 system int mnOrientation; // in 0-3600 system
// data for bidi and glyph+script fallback // data for bidi and glyph+script fallback
......
...@@ -341,11 +341,12 @@ void CTLayout::drawCTLine(AquaSalGraphics& rAquaGraphics, CTLineRef ctline, cons ...@@ -341,11 +341,12 @@ void CTLayout::drawCTLine(AquaSalGraphics& rAquaGraphics, CTLineRef ctline, cons
// the view is vertically flipped => flipped glyphs // the view is vertically flipped => flipped glyphs
// so apply a temporary transformation that it flips back // so apply a temporary transformation that it flips back
// also compensate if the font was size limited // also compensate if the font was size limited
SAL_INFO( "vcl.ct", "CGContextSaveGState(" << rAquaGraphics.mrContext << ")" ); CGContextRef context = rAquaGraphics.mrContext;
CGContextSaveGState( rAquaGraphics.mrContext ); SAL_INFO( "vcl.ct", "CGContextSaveGState(" << context << ")" );
SAL_INFO( "vcl.ct", "CGContextScaleCTM(" << rAquaGraphics.mrContext << ",1.0,-1.0)" ); CGContextSaveGState( context );
CGContextScaleCTM( rAquaGraphics.mrContext, 1.0, -1.0 ); SAL_INFO( "vcl.ct", "CGContextScaleCTM(" << context << ",1.0,-1.0)" );
CGContextSetShouldAntialias( rAquaGraphics.mrContext, !rAquaGraphics.mbNonAntialiasedText ); CGContextScaleCTM( context, 1.0, -1.0 );
CGContextSetShouldAntialias( context, !rAquaGraphics.mbNonAntialiasedText );
// set the text transformation (e.g. position) // set the text transformation (e.g. position)
CGPoint aTextPos = GetTextDrawPosition(); CGPoint aTextPos = GetTextDrawPosition();
...@@ -353,49 +354,46 @@ void CTLayout::drawCTLine(AquaSalGraphics& rAquaGraphics, CTLineRef ctline, cons ...@@ -353,49 +354,46 @@ void CTLayout::drawCTLine(AquaSalGraphics& rAquaGraphics, CTLineRef ctline, cons
if( pStyle->mfFontRotation != 0.0 ) if( pStyle->mfFontRotation != 0.0 )
{ {
const CGFloat fRadians = pStyle->mfFontRotation; const CGFloat fRadians = pStyle->mfFontRotation;
SAL_INFO( "vcl.ct", "CGContextRotateCTM(" << rAquaGraphics.mrContext << "," << +fRadians << ")" ); SAL_INFO( "vcl.ct", "CGContextRotateCTM(" << context << "," << +fRadians << ")" );
CGContextRotateCTM( rAquaGraphics.mrContext, +fRadians ); CGContextRotateCTM( context, +fRadians );
const CGAffineTransform aInvMatrix = CGAffineTransformMakeRotation( -fRadians ); const CGAffineTransform aInvMatrix = CGAffineTransformMakeRotation( -fRadians );
aTextPos = CGPointApplyAffineTransform( aTextPos, aInvMatrix ); aTextPos = CGPointApplyAffineTransform( aTextPos, aInvMatrix );
} }
SAL_INFO( "vcl.ct", "CGContextSetTextPosition(" << rAquaGraphics.mrContext << "," << aTextPos << ")" ); SAL_INFO( "vcl.ct", "CGContextSetTextPosition(" << context << "," << aTextPos << ")" );
CGContextSetTextPosition( rAquaGraphics.mrContext, aTextPos.x, aTextPos.y ); CGContextSetTextPosition( context, aTextPos.x, aTextPos.y );
#ifndef IOS #ifndef IOS
// request an update of the to-be-changed window area // request an update of the to-be-changed window area
if( rAquaGraphics.IsWindowGraphics() ) if( rAquaGraphics.IsWindowGraphics() )
{ {
const CGRect aInkRect = CTLineGetImageBounds( mpCTLine, rAquaGraphics.mrContext ); const CGRect aInkRect = CTLineGetImageBounds( mpCTLine, context );
const CGRect aRefreshRect = CGContextConvertRectToDeviceSpace( rAquaGraphics.mrContext, aInkRect ); const CGRect aRefreshRect = CGContextConvertRectToDeviceSpace( context, aInkRect );
rAquaGraphics.RefreshRect( aRefreshRect ); rAquaGraphics.RefreshRect( aRefreshRect );
} }
#endif #endif
// set the text color as fill color (see kCTForegroundColorFromContextAttributeName) // set the text color as fill color (see kCTForegroundColorFromContextAttributeName)
CGContextSetFillColor( rAquaGraphics.mrContext, rAquaGraphics.maTextColor.AsArray() ); CGContextSetFillColor( context, rAquaGraphics.maTextColor.AsArray() );
SAL_INFO( "vcl.ct", "CTLineDraw(" << ctline << "," << rAquaGraphics.mrContext << ")" ); SAL_INFO( "vcl.ct", "CTLineDraw(" << ctline << "," << context << ")" );
// draw the text // draw the text
CTLineDraw( ctline, rAquaGraphics.mrContext ); CTLineDraw( ctline, context );
if(mnLayoutFlags & SAL_LAYOUT_DRAW_BULLET) if(mnLayoutFlags & SAL_LAYOUT_DRAW_BULLET)
{ {
CFArrayRef runArray = CTLineGetGlyphRuns(ctline); CFArrayRef runArray = CTLineGetGlyphRuns(ctline);
CFIndex runCount = CFArrayGetCount(runArray); CFIndex runCount = CFArrayGetCount(runArray);
CFIndex runIndex = 0; for (CFIndex runIndex = 0; runIndex < runCount; runIndex++)
CTLineRef ctlinebullet = 0;
OUString sBullet((sal_Unicode)0xb7); // centered bullet
for (; runIndex < runCount; runIndex++)
{ {
CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex); CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex);
CFIndex runGlyphCount = CTRunGetGlyphCount(run); CFIndex runGlyphCount = CTRunGetGlyphCount(run);
CGPoint position; CGPoint position;
CGSize advance;
CFIndex runGlyphIndex = 0; CFIndex runGlyphIndex = 0;
CFIndex stringIndice = 0; CFIndex stringIndice = 0;
...@@ -407,36 +405,32 @@ void CTLayout::drawCTLine(AquaSalGraphics& rAquaGraphics, CTLineRef ctline, cons ...@@ -407,36 +405,32 @@ void CTLayout::drawCTLine(AquaSalGraphics& rAquaGraphics, CTLineRef ctline, cons
UniChar curChar = CFStringGetCharacterAtIndex (CFAttributedStringGetString(mpAttrString), stringIndice); UniChar curChar = CFStringGetCharacterAtIndex (CFAttributedStringGetString(mpAttrString), stringIndice);
if(curChar == ' ') if(curChar == ' ')
{ {
CGFloat ascent;
CGFloat descent;
CGFloat leading;
double fWidth = CTRunGetTypographicBounds ( run, glyphRange,
&ascent, &descent, &leading);
CTRunGetPositions(run, glyphRange, &position); CTRunGetPositions(run, glyphRange, &position);
// print a dot CTRunGetAdvances(run, glyphRange, &advance);
if(!ctlinebullet) CGRect bulletRect = NSMakeRect(aTextPos.x + position.x + advance.width / 4,
{ aTextPos.y + position.y + ascent / 3 - fWidth / 2, fWidth / 2, fWidth / 2);
CFStringRef aCFText = CFStringCreateWithCharactersNoCopy( NULL, CGContextSaveGState(context);
sBullet.getStr(), RGBAColor bulletColor(MAKE_SALCOLOR(0x26, 0x8b, 0xd2 )); // NON_PRINTING_CHARACTER_COLOR
1, CGContextSetFillColor( context, bulletColor.AsArray() );
kCFAllocatorNull ); CGContextSetStrokeColor(context, bulletColor.AsArray());
// CFAttributedStringCreate copies the attribues parameter
CFAttributedStringRef bulletAttrString = CFAttributedStringCreate( NULL, aCFText, mpTextStyle->GetStyleDict() ); CGContextBeginPath(context);
ctlinebullet = CTLineCreateWithAttributedString( bulletAttrString ); CGContextAddEllipseInRect(context, bulletRect);
CFRelease( aCFText); CGContextDrawPath(context, kCGPathFillStroke); // Or kCGPathFill
CFRelease( bulletAttrString); CGContextRestoreGState(context);
RGBAColor bulletColor(MAKE_SALCOLOR(0x26, 0x8b, 0xd2 )); // NON_PRINTING_CHARACTER_COLOR
CGContextSetFillColor( rAquaGraphics.mrContext, bulletColor.AsArray() );
}
CGContextSetTextPosition( rAquaGraphics.mrContext, aTextPos.x + position.x, position.y + aTextPos.y );
CTLineDraw(ctlinebullet, rAquaGraphics.mrContext);
} }
} }
} }
if(ctlinebullet)
{
CFRelease(ctlinebullet);
}
} }
// restore the original graphic context transformations // restore the original graphic context transformations
SAL_INFO( "vcl.ct", "CGContextRestoreGState(" << rAquaGraphics.mrContext << ")" ); SAL_INFO( "vcl.ct", "CGContextRestoreGState(" << context << ")" );
CGContextRestoreGState( rAquaGraphics.mrContext ); CGContextRestoreGState( context );
} }
void CTLayout::DrawText( SalGraphics& rGraphics ) const void CTLayout::DrawText( SalGraphics& rGraphics ) const
......
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