bool SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates(Data* queryData, const SVGTextFragment& fragment, int& startPosition, int& endPosition) const { // Reuse the same logic used for text selection & painting, to map our query start/length into start/endPositions of the current text fragment. startPosition -= queryData->processedCharacters; endPosition -= queryData->processedCharacters; // <startPosition, endPosition> is now a tuple of offsets relative to the current text box. // Compute the offsets of the fragment in the same offset space. int fragmentStartInBox = fragment.characterOffset - queryData->textBox->start(); int fragmentEndInBox = fragmentStartInBox + fragment.length; // Check if the ranges intersect. startPosition = std::max(startPosition, fragmentStartInBox); endPosition = std::min(endPosition, fragmentEndInBox); if (startPosition >= endPosition) return false; modifyStartEndPositionsRespectingLigatures(queryData, fragment, startPosition, endPosition); if (!queryData->textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, startPosition, endPosition)) return false; ASSERT(startPosition < endPosition); return true; }
bool SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates(Data* queryData, const SVGTextFragment& fragment, int& startPosition, int& endPosition) const { // Reuse the same logic used for text selection & painting, to map our query start/length into start/endPositions of the current text fragment. startPosition -= queryData->processedCharacters; endPosition -= queryData->processedCharacters; if (startPosition >= endPosition || startPosition < 0 || endPosition < 0) return false; modifyStartEndPositionsRespectingLigatures(queryData, startPosition, endPosition); if (!queryData->textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, startPosition, endPosition)) return false; ASSERT(startPosition < endPosition); return true; }
static bool mapStartEndPositionsIntoFragmentCoordinates(const QueryData* queryData, const SVGTextFragment& fragment, int& startPosition, int& endPosition) { unsigned boxStart = queryData->currentOffset; // Make <startPosition, endPosition> offsets relative to the current text box. startPosition -= boxStart; endPosition -= boxStart; // Reuse the same logic used for text selection & painting, to map our // query start/length into start/endPositions of the current text fragment. if (!queryData->textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, startPosition, endPosition)) return false; modifyStartEndPositionsRespectingLigatures(queryData, fragment, startPosition, endPosition); ASSERT(startPosition < endPosition); return true; }