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:
// 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++ ) {
......
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