Bug 889219. Part 2: Clean up string usage for page numbers/formats. r=mats
This commit is contained in:
@@ -205,7 +205,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
||||
// values
|
||||
NS_NAMED_LITERAL_STRING(kPageAndTotal, "&PT");
|
||||
if (aStr.Find(kPageAndTotal) != kNotFound) {
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumAndTotalsFormat, mPageNum, mTotNumPages);
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumAndTotalsFormat.get(), mPageNum, mTotNumPages);
|
||||
aNewStr.ReplaceSubstring(kPageAndTotal.get(), uStr);
|
||||
nsMemory::Free(uStr);
|
||||
}
|
||||
@@ -214,7 +214,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
||||
// and replace the page number code with the actual value
|
||||
NS_NAMED_LITERAL_STRING(kPage, "&P");
|
||||
if (aStr.Find(kPage) != kNotFound) {
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat, mPageNum);
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat.get(), mPageNum);
|
||||
aNewStr.ReplaceSubstring(kPage.get(), uStr);
|
||||
nsMemory::Free(uStr);
|
||||
}
|
||||
@@ -231,7 +231,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
||||
|
||||
NS_NAMED_LITERAL_STRING(kPageTotal, "&L");
|
||||
if (aStr.Find(kPageTotal) != kNotFound) {
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat, mTotNumPages);
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat.get(), mTotNumPages);
|
||||
aNewStr.ReplaceSubstring(kPageTotal.get(), uStr);
|
||||
nsMemory::Free(uStr);
|
||||
}
|
||||
|
||||
@@ -61,8 +61,6 @@ GetLayoutPrintingLog()
|
||||
nsSharedPageData::nsSharedPageData() :
|
||||
mDateTimeStr(nullptr),
|
||||
mHeadFootFont(nullptr),
|
||||
mPageNumFormat(nullptr),
|
||||
mPageNumAndTotalsFormat(nullptr),
|
||||
mReflowSize(0,0),
|
||||
mReflowMargin(0,0,0,0),
|
||||
mEdgePaperMargin(0,0,0,0),
|
||||
@@ -75,8 +73,6 @@ nsSharedPageData::~nsSharedPageData()
|
||||
{
|
||||
nsMemory::Free(mDateTimeStr);
|
||||
delete mHeadFootFont;
|
||||
nsMemory::Free(mPageNumFormat);
|
||||
nsMemory::Free(mPageNumAndTotalsFormat);
|
||||
}
|
||||
|
||||
nsIFrame*
|
||||
@@ -390,12 +386,7 @@ nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char
|
||||
pageNumberFormat.AssignASCII(aDefPropVal);
|
||||
}
|
||||
|
||||
// Sets the format into a static data member which will own the memory and free it
|
||||
PRUnichar* uStr = ToNewUnicode(pageNumberFormat);
|
||||
if (uStr != nullptr) {
|
||||
SetPageNumberFormat(uStr, aPageNumOnly); // nsPageFrame will own the memory
|
||||
}
|
||||
|
||||
SetPageNumberFormat(pageNumberFormat, aPageNumOnly);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -836,20 +827,13 @@ nsSimplePageSequenceFrame::GetType() const
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsSimplePageSequenceFrame::SetPageNumberFormat(PRUnichar * aFormatStr, bool aForPageNumOnly)
|
||||
nsSimplePageSequenceFrame::SetPageNumberFormat(const nsAString& aFormatStr, bool aForPageNumOnly)
|
||||
{
|
||||
NS_ASSERTION(aFormatStr != nullptr, "Format string cannot be null!");
|
||||
NS_ASSERTION(mPageData != nullptr, "mPageData string cannot be null!");
|
||||
|
||||
if (aForPageNumOnly) {
|
||||
if (mPageData->mPageNumFormat != nullptr) {
|
||||
nsMemory::Free(mPageData->mPageNumFormat);
|
||||
}
|
||||
mPageData->mPageNumFormat = aFormatStr;
|
||||
} else {
|
||||
if (mPageData->mPageNumAndTotalsFormat != nullptr) {
|
||||
nsMemory::Free(mPageData->mPageNumAndTotalsFormat);
|
||||
}
|
||||
mPageData->mPageNumAndTotalsFormat = aFormatStr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public:
|
||||
|
||||
PRUnichar * mDateTimeStr;
|
||||
nsFont * mHeadFootFont;
|
||||
PRUnichar * mPageNumFormat;
|
||||
PRUnichar * mPageNumAndTotalsFormat;
|
||||
nsString mPageNumFormat;
|
||||
nsString mPageNumAndTotalsFormat;
|
||||
nsString mDocTitle;
|
||||
nsString mDocURL;
|
||||
|
||||
@@ -109,7 +109,7 @@ protected:
|
||||
|
||||
// SharedPageData Helper methods
|
||||
void SetDateTimeStr(PRUnichar * aDateTimeStr);
|
||||
void SetPageNumberFormat(PRUnichar * aFormatStr, bool aForPageNumOnly);
|
||||
void SetPageNumberFormat(const nsAString& aFormatStr, bool aForPageNumOnly);
|
||||
|
||||
// Sets the frame desired size to the size of the viewport, or the given
|
||||
// nscoords, whichever is larger. Print scaling is applied in this function.
|
||||
|
||||
Reference in New Issue
Block a user