зеркало из https://github.com/mozilla/gecko-dev.git
Bug 850655 - Make CharIterator::Next() not crash when at the end of text. r=longsonr
--HG-- extra : rebase_source : 830fa0fda257401a77c1aae8686aa5ab6db18d86
This commit is contained in:
Родитель
d93927f49f
Коммит
9e9a56db86
|
@ -75,16 +75,9 @@ SVGTextContentElement::GetSubStringLength(uint32_t charnum, uint32_t nchars, Err
|
|||
if (!textFrame)
|
||||
return 0.0f;
|
||||
|
||||
uint32_t charcount = textFrame->GetNumberOfChars(this);
|
||||
if (charcount <= charnum || nchars > charcount - charnum) {
|
||||
rv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (nchars == 0)
|
||||
return 0.0f;
|
||||
|
||||
return textFrame->GetSubStringLength(this, charnum, nchars);
|
||||
float length = 0.0f;
|
||||
rv = textFrame->GetSubStringLength(this, charnum, nchars, &length);
|
||||
return length;
|
||||
} else {
|
||||
nsSVGTextContainerFrame* metrics = GetTextContainerFrame();
|
||||
if (!metrics)
|
||||
|
|
|
@ -2293,6 +2293,9 @@ CharIterator::Next()
|
|||
bool
|
||||
CharIterator::Next(uint32_t aCount)
|
||||
{
|
||||
if (aCount == 0 && AtEnd()) {
|
||||
return false;
|
||||
}
|
||||
while (aCount) {
|
||||
if (!Next()) {
|
||||
return false;
|
||||
|
@ -2479,6 +2482,10 @@ CharIterator::GetGlyphPartialAdvance(uint32_t aPartOffset, uint32_t aPartLength,
|
|||
bool
|
||||
CharIterator::NextCharacter()
|
||||
{
|
||||
if (AtEnd()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mTextElementCharIndex++;
|
||||
|
||||
// Advance within the current text run.
|
||||
|
@ -3646,9 +3653,10 @@ nsSVGTextFrame2::GetComputedTextLength(nsIContent* aContent)
|
|||
* Implements the SVG DOM GetSubStringLength method for the specified
|
||||
* text content element.
|
||||
*/
|
||||
float
|
||||
nsresult
|
||||
nsSVGTextFrame2::GetSubStringLength(nsIContent* aContent,
|
||||
uint32_t charnum, uint32_t nchars)
|
||||
uint32_t charnum, uint32_t nchars,
|
||||
float* aResult)
|
||||
{
|
||||
UpdateGlyphPositioning(false);
|
||||
|
||||
|
@ -3656,11 +3664,16 @@ nsSVGTextFrame2::GetSubStringLength(nsIContent* aContent,
|
|||
// aContent to global character indices.
|
||||
CharIterator chit(this, CharIterator::eAddressable, aContent);
|
||||
if (!chit.AdvanceToSubtree() ||
|
||||
chit.AtEnd() ||
|
||||
!chit.Next(charnum) ||
|
||||
chit.IsAfterSubtree()) {
|
||||
return 0.0f;
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
||||
if (nchars == 0) {
|
||||
*aResult = 0.0f;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
charnum = chit.TextElementCharIndex();
|
||||
chit.NextWithinSubtree(nchars);
|
||||
nchars = chit.TextElementCharIndex() - charnum;
|
||||
|
@ -3703,8 +3716,9 @@ nsSVGTextFrame2::GetSubStringLength(nsIContent* aContent,
|
|||
float cssPxPerDevPx = presContext->
|
||||
AppUnitsToFloatCSSPixels(presContext->AppUnitsPerDevPixel());
|
||||
|
||||
return presContext->AppUnitsToGfxUnits(textLength) *
|
||||
cssPxPerDevPx / mFontSizeScaleFactor;
|
||||
*aResult = presContext->AppUnitsToGfxUnits(textLength) *
|
||||
cssPxPerDevPx / mFontSizeScaleFactor;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3752,7 +3766,6 @@ nsSVGTextFrame2::GetStartPositionOfChar(nsIContent* aContent,
|
|||
|
||||
CharIterator it(this, CharIterator::eAddressable, aContent);
|
||||
if (!it.AdvanceToSubtree() ||
|
||||
it.AtEnd() ||
|
||||
!it.Next(aCharNum)) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
@ -3777,7 +3790,6 @@ nsSVGTextFrame2::GetEndPositionOfChar(nsIContent* aContent,
|
|||
|
||||
CharIterator it(this, CharIterator::eAddressable, aContent);
|
||||
if (!it.AdvanceToSubtree() ||
|
||||
it.AtEnd() ||
|
||||
!it.Next(aCharNum)) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
@ -3815,7 +3827,6 @@ nsSVGTextFrame2::GetExtentOfChar(nsIContent* aContent,
|
|||
|
||||
CharIterator it(this, CharIterator::eAddressable, aContent);
|
||||
if (!it.AdvanceToSubtree() ||
|
||||
it.AtEnd() ||
|
||||
!it.Next(aCharNum)) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
@ -3867,7 +3878,6 @@ nsSVGTextFrame2::GetRotationOfChar(nsIContent* aContent,
|
|||
|
||||
CharIterator it(this, CharIterator::eAddressable, aContent);
|
||||
if (!it.AdvanceToSubtree() ||
|
||||
it.AtEnd() ||
|
||||
!it.Next(aCharNum)) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
|
|
@ -259,7 +259,8 @@ public:
|
|||
// SVG DOM text methods:
|
||||
uint32_t GetNumberOfChars(nsIContent* aContent);
|
||||
float GetComputedTextLength(nsIContent* aContent);
|
||||
float GetSubStringLength(nsIContent* aContent, uint32_t charnum, uint32_t nchars);
|
||||
nsresult GetSubStringLength(nsIContent* aContent, uint32_t charnum,
|
||||
uint32_t nchars, float* aResult);
|
||||
int32_t GetCharNumAtPosition(nsIContent* aContent, mozilla::nsISVGPoint* point);
|
||||
|
||||
nsresult GetStartPositionOfChar(nsIContent* aContent, uint32_t aCharNum,
|
||||
|
|
Загрузка…
Ссылка в новой задаче