+ // If is likely the user query consecutively for the number of lines with the same
+ // glyph index and number of glyphs, use the cache could be considered.
+ GetLineCache& lineCache = mImpl->mGetLineCache;
+
+ // Cache the glyph index and number of glyphs to be used in the GetLinesOfGlyphRange().
+ lineCache.glyphIndex = glyphIndex;
+ lineCache.numberOfGlyphs = numberOfGlyphs;
+
+ // Check first if the query is for the total number of glyphs.
+ const Length totalNumberOfGlyphs = mImpl->mGlyphs.Count();
+
+ if( ( 0u == glyphIndex ) &&
+ ( totalNumberOfGlyphs == numberOfGlyphs ) )
+ {
+ lineCache.firstLine = 0u;
+ lineCache.numberOfLines = mImpl->mLines.Count();
+
+ return lineCache.numberOfLines;
+ }
+
+ // Initialize the number of lines and the first line.
+ lineCache.numberOfLines = 0u;
+ lineCache.firstLine = 0u;
+ bool firstLineFound = false;
+
+ const Vector<LineRun>& modelLines = mImpl->mLines;
+ const GlyphIndex lastGlyphIndex = glyphIndex + numberOfGlyphs;
+
+ // Traverse the lines and cound those lines within the range of glyphs.
+ for( Vector<LineRun>::ConstIterator it = modelLines.Begin(),
+ endIt = modelLines.End();
+ it != endIt;
+ ++it )
+ {
+ const LineRun& line = *it;
+
+ if( ( line.glyphIndex + line.numberOfGlyphs > glyphIndex ) &&
+ ( lastGlyphIndex > line.glyphIndex ) )
+ {
+ firstLineFound = true;
+ ++lineCache.numberOfLines;
+ }
+ else if( lastGlyphIndex <= line.glyphIndex )
+ {
+ // nothing else to do.
+ break;
+ }
+
+ if( !firstLineFound )
+ {
+ ++lineCache.firstLine;
+ }
+ }
+
+ return lineCache.numberOfLines;