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
This commit is contained in:
@@ -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) :
|
|||||||
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 )
|
|||||||
|
|
||||||
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,16 +236,25 @@ 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);
|
||||||
|
|
||||||
|
for (CFIndex nRun = 0; nRun < nRuns; nRun++)
|
||||||
{
|
{
|
||||||
CTFontRef pCTFont = mpGlyphFonts[i];
|
CTRunRef pRun = (CTRunRef)CFArrayGetValueAtIndex(pRuns, nRun);
|
||||||
|
if (!pRun)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Find the number of glyphs using the same font
|
const CFIndex nGlyphs = CTRunGetGlyphCount(pRun);
|
||||||
int nGlyphs = 1;
|
if (nGlyphs)
|
||||||
while ((i + nGlyphs < mnGlyphCount) && CFEqual(mpGlyphFonts[i + nGlyphs], pCTFont))
|
{
|
||||||
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);
|
CGFontRef pCGFont = CTFontCopyGraphicsFont(pCTFont, NULL);
|
||||||
if (!pCGFont) {
|
if (!pCGFont) {
|
||||||
SAL_INFO("vcl.coretext.layout", "Error pCGFont is NULL");
|
SAL_INFO("vcl.coretext.layout", "Error pCGFont is NULL");
|
||||||
@@ -263,9 +265,8 @@ void CoreTextLayout::DrawText( SalGraphics& rGraphics ) const
|
|||||||
CFRelease(pCGFont);
|
CFRelease(pCGFont);
|
||||||
CGContextSetFontSize(gr.mrContext, CTFontGetSize(pCTFont));
|
CGContextSetFontSize(gr.mrContext, CTFontGetSize(pCTFont));
|
||||||
|
|
||||||
CGContextShowGlyphsWithAdvances(gr.mrContext, &mpGlyphs[i], &mpGlyphAdvances[i], nGlyphs);
|
CGContextShowGlyphsWithAdvances(gr.mrContext, pGlyphs, pAdvances, nGlyphs);
|
||||||
|
}
|
||||||
i += nGlyphs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef IOS
|
#ifndef IOS
|
||||||
@@ -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()
|
|||||||
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()
|
|||||||
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++ ) {
|
||||||
|
Reference in New Issue
Block a user