diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2013-05-17 23:17:54 +0200 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2013-05-18 00:35:52 +0200 |
commit | 81ec93f8448d32933e2697613449baf573b63e42 (patch) | |
tree | a8386b8148fa55d736656f823217a8df8c2d19f1 /vcl/coretext | |
parent | d1bd0cbb41f6377607a1c18589eb5e24b16988ed (diff) |
Simplify Core Text drawing
No need to keep a fonts array around; we don’t modify the glyph array in
anyway so we can just query the CTLine directly.
Change-Id: I24fd49b8fcc8391de7fe132db60bc81bc9941a81
Diffstat (limited to 'vcl/coretext')
-rw-r--r-- | vcl/coretext/salcoretextlayout.cxx | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/vcl/coretext/salcoretextlayout.cxx b/vcl/coretext/salcoretextlayout.cxx index e4afc8d5a459..650506d61b84 100644 --- a/vcl/coretext/salcoretextlayout.cxx +++ b/vcl/coretext/salcoretextlayout.cxx @@ -75,8 +75,6 @@ private: // mutable members since these details are all lazy initialized mutable int mnGlyphCount; - mutable CTFontRef* mpGlyphFonts; - mutable CGGlyph* mpGlyphs; mutable CGFloat* mpCharWidths; mutable int* mpGlyphs2Chars; @@ -106,7 +104,6 @@ CoreTextLayout::CoreTextLayout(CoreTextStyleInfo* style) : mpStyle(style), mnCharCount(-1), mnGlyphCount(-1), - mpGlyphFonts(NULL), mpGlyphs(NULL), mpCharWidths(NULL), mpGlyphs2Chars(NULL), @@ -183,10 +180,6 @@ void CoreTextLayout::Justify( long nNewWidth ) void CoreTextLayout::InvalidateMeasurements() { - if( mpGlyphFonts ) { - delete[] mpGlyphFonts; - mpGlyphFonts = NULL; - } if( mpGlyphs ) { delete[] mpGlyphs; mpGlyphs = NULL; @@ -243,29 +236,37 @@ void CoreTextLayout::DrawText( SalGraphics& rGraphics ) const CGContextTranslateCTM(gr.mrContext, pos.X(), pos.Y()); - int i = 0; - while (i < mnGlyphCount) - { - CTFontRef pCTFont = mpGlyphFonts[i]; + CFArrayRef pRuns = CTLineGetGlyphRuns(mpLine); + const CFIndex nRuns = CFArrayGetCount(pRuns); - // Find the number of glyphs using the same font - int nGlyphs = 1; - while ((i + nGlyphs < mnGlyphCount) && CFEqual(mpGlyphFonts[i + nGlyphs], pCTFont)) - nGlyphs++; - - CGFontRef pCGFont = CTFontCopyGraphicsFont(pCTFont, NULL); - if (!pCGFont) { - SAL_INFO("vcl.coretext.layout", "Error pCGFont is NULL"); - return; - } + for (CFIndex nRun = 0; nRun < nRuns; nRun++) + { + CTRunRef pRun = (CTRunRef)CFArrayGetValueAtIndex(pRuns, nRun); + if (!pRun) + continue; - CGContextSetFont(gr.mrContext, pCGFont); - CFRelease(pCGFont); - CGContextSetFontSize(gr.mrContext, CTFontGetSize(pCTFont)); + const CFIndex nGlyphs = CTRunGetGlyphCount(pRun); + if (nGlyphs) + { + CGGlyph pGlyphs[nGlyphs]; + CGSize pAdvances[nGlyphs]; + CTRunGetGlyphs(pRun, CFRangeMake(0, 0), pGlyphs); + CTRunGetAdvances(pRun, CFRangeMake(0, 0), pAdvances); + + CFDictionaryRef aAttributes = CTRunGetAttributes(pRun); + CTFontRef pCTFont = (CTFontRef)CFDictionaryGetValue(aAttributes, kCTFontAttributeName); + CGFontRef pCGFont = CTFontCopyGraphicsFont(pCTFont, NULL); + if (!pCGFont) { + SAL_INFO("vcl.coretext.layout", "Error pCGFont is NULL"); + return; + } - CGContextShowGlyphsWithAdvances(gr.mrContext, &mpGlyphs[i], &mpGlyphAdvances[i], nGlyphs); + CGContextSetFont(gr.mrContext, pCGFont); + CFRelease(pCGFont); + CGContextSetFontSize(gr.mrContext, CTFontGetSize(pCTFont)); - i += nGlyphs; + CGContextShowGlyphsWithAdvances(gr.mrContext, pGlyphs, pAdvances, nGlyphs); + } } #ifndef IOS @@ -596,7 +597,6 @@ void CoreTextLayout::GetMeasurements() { InvalidateMeasurements(); - mpGlyphFonts = new CTFontRef[ mnGlyphCount ]; mpGlyphs = new CGGlyph[ mnGlyphCount ]; mpCharWidths = new CGFloat[ mnCharCount ]; mpGlyphs2Chars = new int[ mnGlyphCount ]; @@ -613,9 +613,6 @@ void CoreTextLayout::GetMeasurements() if ( !run ) continue; - CFDictionaryRef runAttributes = CTRunGetAttributes(run); - CTFontRef runFont = (CTFontRef)CFDictionaryGetValue(runAttributes, kCTFontAttributeName); - std::ostringstream glyphPositionInfo; std::ostringstream glyphAdvancesInfo; std::ostringstream charWidthInfo; @@ -643,8 +640,6 @@ void CoreTextLayout::GetMeasurements() mpGlyphs2Chars[ lineGlyphIx ] = charIx; mpCharWidths[ charIx ] = mpGlyphAdvances[ lineGlyphIx ].width; - - mpGlyphFonts[ lineGlyphIx ] = runFont; } #ifdef SAL_LOG_INFO for ( int i = 0; i < runGlyphCount; i++ ) { |