Kaydet (Commit) 81ec93f8 authored tarafından Khaled Hosny's avatar Khaled Hosny

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
üst d1bd0cbb
...@@ -75,8 +75,6 @@ private: ...@@ -75,8 +75,6 @@ private:
// mutable members since these details are all lazy initialized // mutable members since these details are all lazy initialized
mutable int mnGlyphCount; mutable int mnGlyphCount;
mutable CTFontRef* mpGlyphFonts;
mutable CGGlyph* mpGlyphs; mutable CGGlyph* mpGlyphs;
mutable CGFloat* mpCharWidths; mutable CGFloat* mpCharWidths;
mutable int* mpGlyphs2Chars; mutable int* mpGlyphs2Chars;
...@@ -106,7 +104,6 @@ CoreTextLayout::CoreTextLayout(CoreTextStyleInfo* style) : ...@@ -106,7 +104,6 @@ CoreTextLayout::CoreTextLayout(CoreTextStyleInfo* style) :
mpStyle(style), mpStyle(style),
mnCharCount(-1), mnCharCount(-1),
mnGlyphCount(-1), mnGlyphCount(-1),
mpGlyphFonts(NULL),
mpGlyphs(NULL), mpGlyphs(NULL),
mpCharWidths(NULL), mpCharWidths(NULL),
mpGlyphs2Chars(NULL), mpGlyphs2Chars(NULL),
...@@ -183,10 +180,6 @@ void CoreTextLayout::Justify( long nNewWidth ) ...@@ -183,10 +180,6 @@ void CoreTextLayout::Justify( long nNewWidth )
void CoreTextLayout::InvalidateMeasurements() void CoreTextLayout::InvalidateMeasurements()
{ {
if( mpGlyphFonts ) {
delete[] mpGlyphFonts;
mpGlyphFonts = NULL;
}
if( mpGlyphs ) { if( mpGlyphs ) {
delete[] mpGlyphs; delete[] mpGlyphs;
mpGlyphs = NULL; mpGlyphs = NULL;
...@@ -243,29 +236,37 @@ void CoreTextLayout::DrawText( SalGraphics& rGraphics ) const ...@@ -243,29 +236,37 @@ void CoreTextLayout::DrawText( SalGraphics& rGraphics ) const
CGContextTranslateCTM(gr.mrContext, pos.X(), pos.Y()); CGContextTranslateCTM(gr.mrContext, pos.X(), pos.Y());
int i = 0; CFArrayRef pRuns = CTLineGetGlyphRuns(mpLine);
while (i < mnGlyphCount) const CFIndex nRuns = CFArrayGetCount(pRuns);
{
CTFontRef pCTFont = mpGlyphFonts[i];
// Find the number of glyphs using the same font for (CFIndex nRun = 0; nRun < nRuns; nRun++)
int nGlyphs = 1; {
while ((i + nGlyphs < mnGlyphCount) && CFEqual(mpGlyphFonts[i + nGlyphs], pCTFont)) CTRunRef pRun = (CTRunRef)CFArrayGetValueAtIndex(pRuns, nRun);
nGlyphs++; if (!pRun)
continue;
CGFontRef pCGFont = CTFontCopyGraphicsFont(pCTFont, NULL);
if (!pCGFont) {
SAL_INFO("vcl.coretext.layout", "Error pCGFont is NULL");
return;
}
CGContextSetFont(gr.mrContext, pCGFont); const CFIndex nGlyphs = CTRunGetGlyphCount(pRun);
CFRelease(pCGFont); if (nGlyphs)
CGContextSetFontSize(gr.mrContext, CTFontGetSize(pCTFont)); {
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 #ifndef IOS
...@@ -596,7 +597,6 @@ void CoreTextLayout::GetMeasurements() ...@@ -596,7 +597,6 @@ void CoreTextLayout::GetMeasurements()
{ {
InvalidateMeasurements(); InvalidateMeasurements();
mpGlyphFonts = new CTFontRef[ mnGlyphCount ];
mpGlyphs = new CGGlyph[ mnGlyphCount ]; mpGlyphs = new CGGlyph[ mnGlyphCount ];
mpCharWidths = new CGFloat[ mnCharCount ]; mpCharWidths = new CGFloat[ mnCharCount ];
mpGlyphs2Chars = new int[ mnGlyphCount ]; mpGlyphs2Chars = new int[ mnGlyphCount ];
...@@ -613,9 +613,6 @@ void CoreTextLayout::GetMeasurements() ...@@ -613,9 +613,6 @@ void CoreTextLayout::GetMeasurements()
if ( !run ) if ( !run )
continue; continue;
CFDictionaryRef runAttributes = CTRunGetAttributes(run);
CTFontRef runFont = (CTFontRef)CFDictionaryGetValue(runAttributes, kCTFontAttributeName);
std::ostringstream glyphPositionInfo; std::ostringstream glyphPositionInfo;
std::ostringstream glyphAdvancesInfo; std::ostringstream glyphAdvancesInfo;
std::ostringstream charWidthInfo; std::ostringstream charWidthInfo;
...@@ -643,8 +640,6 @@ void CoreTextLayout::GetMeasurements() ...@@ -643,8 +640,6 @@ void CoreTextLayout::GetMeasurements()
mpGlyphs2Chars[ lineGlyphIx ] = charIx; mpGlyphs2Chars[ lineGlyphIx ] = charIx;
mpCharWidths[ charIx ] = mpGlyphAdvances[ lineGlyphIx ].width; mpCharWidths[ charIx ] = mpGlyphAdvances[ lineGlyphIx ].width;
mpGlyphFonts[ lineGlyphIx ] = runFont;
} }
#ifdef SAL_LOG_INFO #ifdef SAL_LOG_INFO
for ( int i = 0; i < runGlyphCount; i++ ) { for ( int i = 0; i < runGlyphCount; i++ ) {
......
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