[Libreoffice-commits] core.git: 4 commits - vcl/coretext
Khaled Hosny
khaledhosny at eglug.org
Fri May 17 15:36:54 PDT 2013
vcl/coretext/salcoretextlayout.cxx | 107 +++++++++++++++----------------------
1 file changed, 46 insertions(+), 61 deletions(-)
New commits:
commit e4088a68aa3d69da60f5a1e93c06ca8be3ff764f
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Fri May 17 23:23:02 2013 +0200
Drop unused mpGlyphPositions array
Change-Id: I858832a41ef140fa9916e05548edf2df6b0af451
diff --git a/vcl/coretext/salcoretextlayout.cxx b/vcl/coretext/salcoretextlayout.cxx
index 650506d..d2c2d48 100644
--- a/vcl/coretext/salcoretextlayout.cxx
+++ b/vcl/coretext/salcoretextlayout.cxx
@@ -81,7 +81,6 @@ private:
mutable CGSize* mpGlyphAdvances;
- mutable CGPoint* mpGlyphPositions;
mutable CTTypesetterRef mpTypesetter;
mutable CTLineRef mpLine;
mutable bool mbHasBoundRectangle;
@@ -108,7 +107,6 @@ CoreTextLayout::CoreTextLayout(CoreTextStyleInfo* style) :
mpCharWidths(NULL),
mpGlyphs2Chars(NULL),
mpGlyphAdvances(NULL),
- mpGlyphPositions(NULL),
mpTypesetter(NULL),
mpLine(NULL),
mbHasBoundRectangle(false),
@@ -196,10 +194,6 @@ void CoreTextLayout::InvalidateMeasurements()
delete[] mpGlyphAdvances;
mpGlyphAdvances = NULL;
}
- if( mpGlyphPositions ) {
- delete[] mpGlyphPositions;
- mpGlyphPositions = NULL;
- }
mbHasBoundRectangle = false;
}
@@ -601,7 +595,6 @@ void CoreTextLayout::GetMeasurements()
mpCharWidths = new CGFloat[ mnCharCount ];
mpGlyphs2Chars = new int[ mnGlyphCount ];
mpGlyphAdvances = new CGSize[ mnGlyphCount ];
- mpGlyphPositions = new CGPoint[ mnGlyphCount ];
CFArrayRef runs = CTLineGetGlyphRuns( mpLine );
const CFIndex nRuns = CFArrayGetCount( runs );
@@ -630,7 +623,6 @@ void CoreTextLayout::GetMeasurements()
CTRunGetGlyphs( run, CFRangeMake( 0, 0 ), &mpGlyphs[ lineGlyphIx ] );
- CTRunGetPositions( run, CFRangeMake( 0, 0 ), &mpGlyphPositions[ lineGlyphIx ] );
CTRunGetAdvances( run, CFRangeMake( 0, 0 ), &mpGlyphAdvances[ lineGlyphIx ] );
for ( CFIndex runGlyphIx = 0 ; runGlyphIx < runGlyphCount; lineGlyphIx++, runGlyphIx++ )
@@ -645,7 +637,7 @@ void CoreTextLayout::GetMeasurements()
for ( int i = 0; i < runGlyphCount; i++ ) {
const int ix = lineRunGlyphStartIx + i;
if ( i < 7 ) {
- glyphPositionInfo << " " << mpGlyphs[ ix ] << "@" << mpGlyphPositions[ ix ];
+ glyphPositionInfo << " " << mpGlyphs[ ix ];
glyphAdvancesInfo << " " << mpGlyphAdvances[ ix ];
} else if (i == 7 ) {
glyphPositionInfo << "...";
commit 81ec93f8448d32933e2697613449baf573b63e42
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Fri May 17 23:17:54 2013 +0200
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
diff --git a/vcl/coretext/salcoretextlayout.cxx b/vcl/coretext/salcoretextlayout.cxx
index e4afc8d..650506d 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++ ) {
commit d1bd0cbb41f6377607a1c18589eb5e24b16988ed
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Fri May 17 22:58:00 2013 +0200
Remove unused variable
isVerticalRun is not used anywhere, remove for now.
Change-Id: I29a9650e3031dc1faaacd13f4aa9fefe661edaa7
diff --git a/vcl/coretext/salcoretextlayout.cxx b/vcl/coretext/salcoretextlayout.cxx
index 03750bc..e4afc8d 100644
--- a/vcl/coretext/salcoretextlayout.cxx
+++ b/vcl/coretext/salcoretextlayout.cxx
@@ -636,13 +636,6 @@ void CoreTextLayout::GetMeasurements()
CTRunGetPositions( run, CFRangeMake( 0, 0 ), &mpGlyphPositions[ lineGlyphIx ] );
CTRunGetAdvances( run, CFRangeMake( 0, 0 ), &mpGlyphAdvances[ lineGlyphIx ] );
- bool isVerticalRun = false;
- CFDictionaryRef aDict = CTRunGetAttributes( run );
- if ( aDict ) {
- const CFBooleanRef aValue = (const CFBooleanRef)CFDictionaryGetValue( aDict, kCTVerticalFormsAttributeName );
- isVerticalRun = (aValue == kCFBooleanTrue);
- }
-
for ( CFIndex runGlyphIx = 0 ; runGlyphIx < runGlyphCount; lineGlyphIx++, runGlyphIx++ )
{
const CFIndex charIx = runStringIndices[ runGlyphIx ];
commit 455e21727572d6ac123781be292053cf13c68237
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Fri May 17 20:49:27 2013 +0200
Fix Core Text GetCaretPositions()
The secondary caret is a special caret that is inserted when the text
changes its direction e.g. between an RTL and LTR segments, not
whatever who wrote this code thought it is.
This should now be more or less the same as ATSUI version (for better or
worse), though it probably makes no difference anyway since
GetCaretPositions(), despite its name, is *not* used for determining
caret positions but only for drawing mnemonic underlines, and we donât
draw any menus by ourselves on Mac.
While at it, adopt variable naming used in the rest of the code (not the
spacing, though. Why any sane person would want no space before opening
parenthesis and space after it!).
Change-Id: I3e8d1db33c899d0c69f65b57f0a52d10cbed1025
diff --git a/vcl/coretext/salcoretextlayout.cxx b/vcl/coretext/salcoretextlayout.cxx
index f1944be..03750bc 100644
--- a/vcl/coretext/salcoretextlayout.cxx
+++ b/vcl/coretext/salcoretextlayout.cxx
@@ -373,20 +373,25 @@ bool CoreTextLayout::GetBoundRect( SalGraphics& rGraphics, Rectangle& rVCLRect )
return true;
}
-void CoreTextLayout::GetCaretPositions( int max_index, sal_Int32* caret_position ) const
+void CoreTextLayout::GetCaretPositions(int nMaxIndex, sal_Int32* pCaretXArray) const
{
- SAL_INFO( "vcl.coretext.layout", "GetCaretPositions(" << this << ",max_index=" << max_index << ")" );
-
- int local_max = max_index < mnCharCount * 2 ? max_index : mnCharCount;
- for( int i = 0 ; i < max_index - 1; i+=2 ) {
- CGFloat primary, secondary;
- primary = CTLineGetOffsetForStringIndex(mpLine, i >> 1, &secondary);
- caret_position[i] = round_to_long(mnBaseAdvance + primary);
- caret_position[i+1] = round_to_long(mnBaseAdvance + secondary);
- i += 2;
- }
- for( int i = local_max ; i < max_index ; ++i ) {
- caret_position[i] = -1;
+ SAL_INFO( "vcl.coretext.layout", "GetCaretPositions(" << this << ",nMaxIndex=" << nMaxIndex << ")" );
+
+ // initialize the caret positions
+ for (int i = 0; i < nMaxIndex; ++i)
+ pCaretXArray[i] = -1;
+
+ for (int i = 0 ; i < mnCharCount; i++)
+ {
+ CGFloat fPrimary, fSecondary;
+ fPrimary = CTLineGetOffsetForStringIndex(mpLine, i, &fSecondary);
+ // update previous trailing position
+ if (i > 0)
+ pCaretXArray[2*i-1] = round_to_long(mnBaseAdvance + fPrimary);
+ // update current leading position
+ if (2*i >= nMaxIndex)
+ break;
+ pCaretXArray[2*i+0] = round_to_long(mnBaseAdvance + fPrimary);
}
}
More information about the Libreoffice-commits
mailing list