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
|
// values
|
||||||
NS_NAMED_LITERAL_STRING(kPageAndTotal, "&PT");
|
NS_NAMED_LITERAL_STRING(kPageAndTotal, "&PT");
|
||||||
if (aStr.Find(kPageAndTotal) != kNotFound) {
|
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);
|
aNewStr.ReplaceSubstring(kPageAndTotal.get(), uStr);
|
||||||
nsMemory::Free(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
|
// and replace the page number code with the actual value
|
||||||
NS_NAMED_LITERAL_STRING(kPage, "&P");
|
NS_NAMED_LITERAL_STRING(kPage, "&P");
|
||||||
if (aStr.Find(kPage) != kNotFound) {
|
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);
|
aNewStr.ReplaceSubstring(kPage.get(), uStr);
|
||||||
nsMemory::Free(uStr);
|
nsMemory::Free(uStr);
|
||||||
}
|
}
|
||||||
@@ -231,7 +231,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|||||||
|
|
||||||
NS_NAMED_LITERAL_STRING(kPageTotal, "&L");
|
NS_NAMED_LITERAL_STRING(kPageTotal, "&L");
|
||||||
if (aStr.Find(kPageTotal) != kNotFound) {
|
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);
|
aNewStr.ReplaceSubstring(kPageTotal.get(), uStr);
|
||||||
nsMemory::Free(uStr);
|
nsMemory::Free(uStr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,8 +61,6 @@ GetLayoutPrintingLog()
|
|||||||
nsSharedPageData::nsSharedPageData() :
|
nsSharedPageData::nsSharedPageData() :
|
||||||
mDateTimeStr(nullptr),
|
mDateTimeStr(nullptr),
|
||||||
mHeadFootFont(nullptr),
|
mHeadFootFont(nullptr),
|
||||||
mPageNumFormat(nullptr),
|
|
||||||
mPageNumAndTotalsFormat(nullptr),
|
|
||||||
mReflowSize(0,0),
|
mReflowSize(0,0),
|
||||||
mReflowMargin(0,0,0,0),
|
mReflowMargin(0,0,0,0),
|
||||||
mEdgePaperMargin(0,0,0,0),
|
mEdgePaperMargin(0,0,0,0),
|
||||||
@@ -75,8 +73,6 @@ nsSharedPageData::~nsSharedPageData()
|
|||||||
{
|
{
|
||||||
nsMemory::Free(mDateTimeStr);
|
nsMemory::Free(mDateTimeStr);
|
||||||
delete mHeadFootFont;
|
delete mHeadFootFont;
|
||||||
nsMemory::Free(mPageNumFormat);
|
|
||||||
nsMemory::Free(mPageNumAndTotalsFormat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsIFrame*
|
nsIFrame*
|
||||||
@@ -390,12 +386,7 @@ nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char
|
|||||||
pageNumberFormat.AssignASCII(aDefPropVal);
|
pageNumberFormat.AssignASCII(aDefPropVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the format into a static data member which will own the memory and free it
|
SetPageNumberFormat(pageNumberFormat, aPageNumOnly);
|
||||||
PRUnichar* uStr = ToNewUnicode(pageNumberFormat);
|
|
||||||
if (uStr != nullptr) {
|
|
||||||
SetPageNumberFormat(uStr, aPageNumOnly); // nsPageFrame will own the memory
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
@@ -836,20 +827,13 @@ nsSimplePageSequenceFrame::GetType() const
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void
|
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!");
|
NS_ASSERTION(mPageData != nullptr, "mPageData string cannot be null!");
|
||||||
|
|
||||||
if (aForPageNumOnly) {
|
if (aForPageNumOnly) {
|
||||||
if (mPageData->mPageNumFormat != nullptr) {
|
|
||||||
nsMemory::Free(mPageData->mPageNumFormat);
|
|
||||||
}
|
|
||||||
mPageData->mPageNumFormat = aFormatStr;
|
mPageData->mPageNumFormat = aFormatStr;
|
||||||
} else {
|
} else {
|
||||||
if (mPageData->mPageNumAndTotalsFormat != nullptr) {
|
|
||||||
nsMemory::Free(mPageData->mPageNumAndTotalsFormat);
|
|
||||||
}
|
|
||||||
mPageData->mPageNumAndTotalsFormat = aFormatStr;
|
mPageData->mPageNumAndTotalsFormat = aFormatStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ public:
|
|||||||
|
|
||||||
PRUnichar * mDateTimeStr;
|
PRUnichar * mDateTimeStr;
|
||||||
nsFont * mHeadFootFont;
|
nsFont * mHeadFootFont;
|
||||||
PRUnichar * mPageNumFormat;
|
nsString mPageNumFormat;
|
||||||
PRUnichar * mPageNumAndTotalsFormat;
|
nsString mPageNumAndTotalsFormat;
|
||||||
nsString mDocTitle;
|
nsString mDocTitle;
|
||||||
nsString mDocURL;
|
nsString mDocURL;
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ protected:
|
|||||||
|
|
||||||
// SharedPageData Helper methods
|
// SharedPageData Helper methods
|
||||||
void SetDateTimeStr(PRUnichar * aDateTimeStr);
|
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
|
// 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.
|
// nscoords, whichever is larger. Print scaling is applied in this function.
|
||||||
|
|||||||
Reference in New Issue
Block a user